This quick guide is a little refresher for those who have been out of the smart contract business for a while, or for newbies who want to learn the very basics of Solidity smart contracts.

What is Solidity

Solidity is the language in which most smart contracts are written. This means that anything from NFTs to Defi dApps might be written in Solidity. it runs on the blockchain and the code is stored there as well. This means you cannot have any bugs since you cannot update the contract once it is deployed.

Luckily for Ethereum, Polygon, and other blockchains have several tenets on which we can test our smart contract’s code before we deploy it to the real world main nets.

New Syntax

For this next part, I will assume you have some programming knowledge. Anything from functions and variables to classes and interfaces. Solidity isn’t hard to learn but it does have its quirks you need to keep in mind.

Mappings

Mappings are a way to store data in Solidity. When given a key, they will retrieve the value for you. For example, the owner of a token given by index.

They are often used to keep track of the owners of tokens. But in more intricate smart contracts they often have lots of uses.

Functions

The syntax for functions is pretty standard across languages. Solidity has a slightly different syntax because of modifiers.

The scope indicates who can call the function. This would be private , public , internal or external . A view function doesn’t cost any gas fees but it can only be read from the chain.

Modifiers

Modifiers make sure that only certain users can execute a function. The most used default modifier is the only owner which makes sure only the owner of the contract can execute the function. But you can make your own.

the _; syntax lets the code return to the function called the modifier. If you call _; the code will assume that the condition has passed.

There are a lot of checks you can do with modifiers that you would otherwise have to do in the function itself. If you are a developer in any other field, this wouldn’t be hard to learn. If you’re a new developer, I might have to write another article for you. Solidity is a language that is fairly new and will change over time. If you want to learn it from scratch without Medium, I highly suggest Crypto Zombies learn the basics of the language.

You can also read the documentation and more examples here.

Tags: , , , , , , , , , , , , , , , , , , ,