Skip to content

Commit a1f90d2

Browse files
committed
Visibility of state variable section added
1 parent 88e4fba commit a1f90d2

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lessons/projects/1.mdx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,20 @@ 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 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.
292+
293+
- **Internal**: A state variable with a `internal` visibility can only be accessed within the smart contract and its subclasses. It can *NOT* be accessed externally.
294+
295+
- **Private**: When a state variable visibility is marked as `private` then it means , that it is only ment to be used within the defined smart contract . No subclasses and no external function should access a variable with a `private` visibility.
296+
297+
#### Which visibility should I use ?
298+
299+
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.
300+
287301
</ContentSideDrawer>
288302

289303
## Creating Functions
@@ -687,10 +701,9 @@ you see the magical spell that is being cast here?
687701
![Wizard Wooshing on Successful Lesson](/assets/lessons/1/img_10.png)
688702

689703
Before you go ahead and tell us: **what your future in web3 is,** have a check
690-
on what you didn’t know a little while ago, and what you know now! *
704+
on what you didn’t know a little while ago, and what you know now! \*
691705

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

695708
How many parameters can we have in an event?
696709

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

701714
Where do the values for event parameters get stored?
702715

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

706718
Do state variables stay permanently on the blockchain?
707719

@@ -710,4 +722,4 @@ Can a view function modify the state of the blockchain?
710722
What can we use a smart contract for?
711723

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

0 commit comments

Comments
 (0)