10 Tips to Quickly Grasp Solidity Programming Language Concepts
This blog post provides 10 tips to quickly grasp concepts of the Solidity programming language. It explains what a Solidity contract is, how events work, and how to use libraries.
Francesco
· Developer Advocate at @dailydotdev · Docker Captain · Public Speaker · Building a 1 Million Community 23% · All the links ➞ https://t.co/2DLpQ5cNoa
-
Solidity is one of the best programming languages for writing Smart Contracts.
— Francesco (@FrancescoCiull4) June 13, 2023
❌But some concepts could be more beginner-friendly.
✅Below are 10 tips to grasp some concepts fast in a matter of minutes
A thread (with visuals).
↓ pic.twitter.com/yYYT3Fi9FU -
Solidity Contract
— Francesco (@FrancescoCiull4) June 13, 2023
A Solidity contract is similar to a class in OOP.
It contains:
· data in state variables that are at a specific address on the Ethereum blockchain.
· functions to modify the variables.
On creation, its constructor (if it exists) is executed once. pic.twitter.com/oyf1ybJ76W -
Events in Solidity
— Francesco (@FrancescoCiull4) June 13, 2023
One of my favorite Solidity features is how events are simply and effectively implemented.
3 Steps:
1. you declare the event (using the event keyword).
2. you fire the event (emit).
3. you handle the event with JS on the frontend. pic.twitter.com/jbyw2fn5A5 -
ERC-20 Token Smart Contract
— Francesco (@FrancescoCiull4) June 13, 2023
It's one of the most essential smart contract standards.
It's used for smart contracts on the Ethereum blockchain for fungible token implementations. pic.twitter.com/qNA8PsHzTw -
Reserved Keywords
— Francesco (@FrancescoCiull4) June 13, 2023
These are the currently reserved keywords in Solidity
A reserved keyword is a word that cannot be used as an identifier (e.g. variable name). pic.twitter.com/Ao94bNNJto -
Function Types
— Francesco (@FrancescoCiull4) June 13, 2023
The type of function, which is declared after the params, defines who can access it:
· the contract itself
· the contracts deriving from it
· the external contracts
Types:
· private
· internal
· external
· public
The default type is internal. pic.twitter.com/T1CCtcuF9q -
View & Pure Functions
— Francesco (@FrancescoCiull4) June 13, 2023
Functions can be declared as view or pure.
VIEW:
· ensure to not modify the state.
· Getter methods are view functions by default.
PURE:
· ensure to not read/modify the state.
· can use the revert/require functions if an error occurs. pic.twitter.com/ccvmFzksLL -
MSG Global Variable
— Francesco (@FrancescoCiull4) June 13, 2023
MSG VARIABLE contains properties to access the blockchain.
· msg.sender: message sender.
· msg.value: Wei sent with msg.
· msg.gas: remaining gas.
· msg.sig: calldata's first 4 bytes.
· msg. data: complete calldata. pic.twitter.com/2CZ47J3YSo -
State and Local Variables
— Francesco (@FrancescoCiull4) June 13, 2023
· State Variables:
Values are permanently stored in contract storage.
· Local Variables:
Values are present till the function is in execution. -
Require
— Francesco (@FrancescoCiull4) June 13, 2023
It makes the function stop executing and throw an error if some condition is not true.
You can also pass a message that will be used when the error is thrown.
It turns complex boilerplate logic into something simple and understandable. pic.twitter.com/vPvBuVzQhJ -
Block global variable.
— Francesco (@FrancescoCiull4) June 13, 2023
In Solidity, global variables are used to access important properties for objects in the blockchain.
One of these is "block".
Its values are:
· basefee
· chainId
· coinbase
· difficulty
· number
· timestamp
-gaslimit pic.twitter.com/G571l7pu4V -
These were 10 tips to learn Solidity
— Francesco (@FrancescoCiull4) June 13, 2023
If this thread has been helpful, share the tweet below and follow @FrancescoCiull4 https://t.co/KlXyfmjUiX