You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/projects/1.mdx
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -284,6 +284,24 @@ contract WAGMI {
284
284
- **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.
285
285
-**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.
286
286
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
+
<ContentCalloutemoji='💡'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
+
287
305
</ContentSideDrawer>
288
306
289
307
## Creating Functions
@@ -689,8 +707,7 @@ you see the magical spell that is being cast here?
689
707
Before you go ahead and tell us: **what your future in web3 is,** have a check
690
708
on what you didn’t know a little while ago, and what you know now! *
691
709
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?
694
711
695
712
How many parameters can we have in an event?
696
713
@@ -700,8 +717,7 @@ Ethereum uses something for transaction fees. What’s it called?
700
717
701
718
Where do the values for event parameters get stored?
702
719
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?
705
721
706
722
Do state variables stay permanently on the blockchain?
707
723
@@ -710,4 +726,4 @@ Can a view function modify the state of the blockchain?
710
726
What can we use a smart contract for?
711
727
712
728
**Now, go to the community in Discord to share your new Open Sourcerer
0 commit comments