Skip to content

Commit aa865d7

Browse files
authored
Merge pull request #159 from shikhar360/variablevisibility
Visibility of state variable section added
2 parents 9b6fd9d + c8c6c70 commit aa865d7

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

lessons/projects/1.mdx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,24 @@ contract WAGMI {
284284
- **Struct:** Solidity allows users to create and define their own type in the form of structures. The structure is a group of different types even though it’s not possible to contain a member of its own type. The structure is a reference type variable which can contain both value types and reference types.
285285
- **Mapping Type**: Stores the data in a key-value pair where a key can be any value types. It is like a hash table or dictionary as in any other programming language, where data can be retrieved by key.
286286

287+
### Visibility of State Variables
288+
289+
In Solidity , there are 3 types of variable visibility modifiers that a developer can use :
290+
291+
- **Public**: If a state variable visibility is marked as `public` then those variables can be used within the smart contract and can be accessed by other contracts as well. Compilers automatically generates functions to read its value when calling the contract, they are called 'getter' functions.
292+
293+
- **Internal**: A state variable with an `internal` visibility can only be accessed within the smart contract and its derived contracts. It can *NOT* be accessed externally. This is the default for state variables when no visibilty is specified.
294+
295+
- **Private**: When a state variable visibility is marked as `private` it is only meant to be used within the defined smart contract . No derived contract can read a variable with a `private` visibility.
296+
297+
<ContentCallout emoji='💡' size='md' variant='info'>
298+
While private and internal are not readable or modifiable from other contracts, its values are set on a public blockchain, making its values visible from the outside world.
299+
</ContentCallout>
300+
301+
#### Which visibility should I use ?
302+
303+
A simple answer to this is , start with giving every variable a `private` visibility then as you move further in contract developement modify variables to `internal` visibility as a next step of modification. Try to use `public` visibility as little as possible in order to be gas efficient and making less vulnerabilities in the smart contract.
304+
287305
</ContentSideDrawer>
288306

289307
## Creating Functions
@@ -689,8 +707,7 @@ you see the magical spell that is being cast here?
689707
Before you go ahead and tell us: **what your future in web3 is,** have a check
690708
on what you didn’t know a little while ago, and what you know now! *
691709

692-
Apart from a user wallet, what else uses a blockchain (Ethereum)
693-
address?
710+
Apart from a user wallet, what else uses a blockchain (Ethereum) address?
694711

695712
How many parameters can we have in an event?
696713

@@ -700,8 +717,7 @@ Ethereum uses something for transaction fees. What’s it called?
700717

701718
Where do the values for event parameters get stored?
702719

703-
What is the use of the **pragma solidity** statement in our smart
704-
contract?
720+
What is the use of the **pragma solidity** statement in our smart contract?
705721

706722
Do state variables stay permanently on the blockchain?
707723

@@ -710,4 +726,4 @@ Can a view function modify the state of the blockchain?
710726
What can we use a smart contract for?
711727

712728
**Now, go to the community in Discord to share your new Open Sourcerer
713-
powers**......and find the answers too!!!
729+
powers**......and find the answers too!!!

0 commit comments

Comments
 (0)