Solidity Revert

In Solidity, the Revert function is used to stop execution of a smart contract, reverting the state to it’s previous version, and refunds the user the remaining gas in the process. Here is an example of revert in a smart contract: Revert can accept an error code, that will be shown if the revert code … Read more

Solidity Array Functions

There are a few functions (or “members”) you can perform on an array in Solidity. Push, Pop, and Remove are the most popular functions, and here’s a smart contract that uses them: In the beginning of this contract, you can see that we create a simple array named “counting” that counts from 0 to 4. … Read more

Solidity Address

An address is a data type in Solidity which holds the value of a contract address or an externally owned address (EOA). Here is a smart contract that uses an address: All addresses are hashes generated using the keccak-256 algorithm. All addresses contain 20 bytes of data, or the equivalent of 160 bits or 40 … Read more

Solidity Booleans

In Solidity, a boolean is a data type that holds a value consisting of true or false. This can be represented with a 1 (for true), or 0 (for false), and the default value is false. Here is an example of a contract that uses a boolean (which is denoted with the keyword “bool”): In … Read more

Solidity Constructors

A constructor in solidity is an optional function created with the “constructor” keyword that initializes the state variables of a contract. A contract can only have one constructor. When a contract is created, the constructor code is executed once and is used to set up the state of the contract during deployment. A constructor can … Read more

Solidity Function Modifiers

Modifiers are keywords added to a function in Solidity, which allows the developer to create a process of code to run before and after the function it is applied to. In general, Modifiers are used to control access or check for important requirements before finishing a function. Here is an example of a modifier: In … Read more

Solidity Enums (Syntax Examples)

Enums (short for “enumerables”) are found in most programming languages and stem from the need for tracking state in a program without relying on magic numbers or space-heavy strings. It is useful to think of them as “booleans”, except with more than 2 positions. Enums are a custom (simple) data type in Solidity that allow … Read more

Solidity Require

The require statement in Solidity is used to check that a conditional is true before continuing with future code. It takes 2 arguments, including the conditional to check, and the error message given when the conditional is false. Here’s an example of when you should use a require statement in Solidity: You can see here … Read more

Struct in Solidity

Structs are reference-type variables that are constructed of multiple other variables and treated as objects. They can be very useful when storing a large amount of data that is all grouped in a similar way. Here is an example of how you can create a new struct, including what you can do with it: In … Read more

Solidity Mapping

In Solidity, a Mapping is a data structure that maps one piece of data to another piece of data. It is useful to think of a mapping as an X-Y table where the X column is one variable, and the Y column is another variable. Here are a few examples of a mapping: One of … Read more