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.
One of my favorite Solidity features so far 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.
It's one of the most important smart contract standards.
It's used for smart contracts on the Ethereum blockchain for fungible token implementations.
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).
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.
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.
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.
- State Variables:
Values are permanently stored in contract storage.
- Local Variables:
Values are present till the function is in execution.
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 will be thrown.
It turns complex boilerplate logic into something simple and understandable.
in Solidity, there are global variables, 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
Here is a GitHub Repository with all the tips day by day, and a list of resources to get started and learn web3 for free.
Currently 1998 Stars.
github.com
More from this author
NFT interesting projects I found on GitHub: · metaplex (2.2k★) · zhuowei/nft_ptr (1.5k★) · nft-image-generator (1.2k★) · decentraland/marketplace (50...
Interesting Solidity Projects on GitHub · ethereum/solidity (13.7k ★) · full-blockchain-solidity-course-py (4.1k ★) · awesome-solidity (3.1k ★) · lea...
JavaScript for Beginners. A thread: https://t.co/2KUl4rwD7d
🐳Docker Threads What is a DOCKERFILE? A Dockerfile is a text document that contains all the commands a user could call on the command line to assem...
Recent Threads
CBSE has systematically rewritten its rulebook to favor Coempt Eduteck. check out the blog. https://t.co/CmdXMo8pMh
SA DULO, MAGTATAGPO. — a filo #taekookau a taekook au wherein taehyung is a famous vlogger who offered a stranger to do the 24 hours jowa challenge w...
I’m not allowed in social situations without supervision anymore https://t.co/qRXclKZQAi
yejisu au | fundamentals of me and you. where yeji was forced to face her past after yuna got her hired as a secretary to a CEO. the CEO? the same...
🚨Rollercoaster NIGHTMARE 8 students dangling 100ft on a stuck Galveston TX roller coaster! … Vertical track failure left them hanging for hours. Fi...
Green flags in friendships that are highly underrated:
Popular Threads
Top 20 Players with the most goals + assists in football history, only players with assists available (following the Opta criteria for assists) Seaso...
Here's 40 TikTok hooks that could make you go viral. (Not in any particular order) //THREAD//
Winning the Chevening Scholarship + 12 Strong Samples of the Chevening Essay There are four important Essays on the Chevening Scholarship application...
Ware County, Ga has broken the Dominion algorithm: Using sequestered Dominion Equipment, Ware County ran a equal number of Trump votes and Biden vote...
Please retweet and share if you support my and others' vaccine injury recoveries. https://t.co/y8xNWwRUOO
1. There are more people added on the list of arrests and executions of famous people but no further intel is available at this time. ARRESTS and EXE...