Solidity Tutorial

The Ultimate Solidity Course

A high quality, in depth Solidity course for experienced developers, free, comprehensive, and trusted by smart contract security experts.
Skip to Contents

Who is this course for?

This course is for experienced programmers. If you don’t already know how to code, we suggest picking up Python or JavaScript first then coming back.

If you are new to Solidity, start at the beginning.

However, Solidity developers of all levels can benefit from the resources here in the later sections discuss very advanced topics such as how Tornado Cash works. We also have the only protocol walkthrough of the Compound V3 codebase.

The only paid bootcamp with a free curriculum

Other bootcamps charge hundreds, sometimes thousands of dollars just to see their curriculum. At RareSkills, we believe the entire community benefits when high quality education is freely available. And by free we mean truly free not gated with an email we can monetize later.

The work is truly a public good.

We do hope you will sign up for our bootcamp though! You’ll get time with instructors and a community who have secured billions of dollars in TLV (total locked value).

RareSkills quality

Although this is not a smart contract security course per se, smart contract security researchers regularly refer to the resources here. Our philosophy is that security comes from deeply understanding what you are doing.

Therefore, we don’t create a large list of topics just for the sake of it. We deeply examine non-obvious issues that even experienced Solidity engineers sometimes miss; having taught many through our Solidity Bootcamp we know where the knowledge gaps frequently lie.

Deep understanding should be the expectation for anyone writing code than manages other people’s crypto. As such, our tutorials prioritize generating strong mental models even if it takes more effort to do so.

Finally, we encourage you to compare our tutorials with others on the same subject (and those generated by an AI chatbot).

We are sure you will be impressed at the level of depth, comprehensiveness, and clarity our articles achieve.

Beginner Solidity Tutorial

No email required! This is for experienced programmers who want to get to the point quickly and immediately practice the information they just gained in a highly optimized topic order. We emphasize the unexpected and unusual aspects of the Solidity language while glossing over things we can reasonably assume to be obvious to a competent developer. Aside from an occasional humorous remark, we’ve made the tutorials as short as possible (but not shorter). Although this is a solidity beginner tutorial, it is intended for experienced coders.

There is a distinction between knowing a language, and knowing a domain. Knowing Python doesn’t make you a data scientist, knowing Javascript doesn’t make you a frontend developer, and knowing Kotlin does not make you an Android developer. Similarly, knowing Solidity does not make you an Ethereum smart contract developer. However, Solidity is a prerequisite for developing smart contracts.

2. Fixed Size Datatypes

Solidity is a typed language
View Tutorial

3. Set up Foundry

The Most popular development framework in 2024
View Tutorial

4. Arithmetic

A quick overview of doing math in Solidity
View Tutorial

5. If Statements

A quick lesson on conditional operators
View Tutorial

6. For loops

Syntax for iterative operators
View Tutorial

8. Nested Arrays

2D and 3D data types
View Tutorial

9. Storage Variables

Using a “database in Web3”
View Tutorial

12. Nested Mappings

Persistent hash maps with multiple levels
View Tutorial

13. msg.sender and address(this)

Determining which wallet is calling the smart contract
View Tutorial

14. Constructor

Configuring the smart contract on deployment
View Tutorial

15. Require

Protecting smart contracts from malicious parameters
View Tutorial

16. ERC-20 Tokens

An introduction to the most fundamental building block of DeFi
View Tutorial

17. Tuples

Batching values together
View Tutorial

18. Application binary interface (ABI encoding)

Solidity’s binary encoding format of choice
View Tutorial

19. Contracts calling other contracts

Learn how composability works in Solidity
View Tutorial

21. Payable functions

Transferring Ether with function calls
View Tutorial

22. Receive

How smart contract can receive ETH transactions
View Tutorial

24. Emitting Events

Leaving an audit trail in smart contracts
View Tutorial

25. Inheritance

Organizing code in large smart contracts
View Tutorial

26. Modifiers

Add re-useable functionality to Solidity function
View Tutorial

28. Constants

How to avoid “magic numbers”
View Tutorial

31. Units of Ethereum: wei, gwei, and ether

Convenient keywords for dealing with large numbers
View Tutorial

32. Structs

How to keep data in groups
View Tutorial

33. Strings

Concatenation, UTF-8 encoding, and more
View Tutorial

34. Unit Testing in Solidity

How to write professional unit tests in Foundry
View Tutorial

Getting Started

Your First Solidity Projects

At this point, you now have enough knowledge to build smart contract projects end to end. If you are new to Solidity we strongly recommend you build these projects, not skip them. You can only learn so much by reading tutorials, some knowledge can only be acquired with practice.

Professional Solidity Style Guide

The purpose of this article is not to rehash the official Solidity Style Guide, which you should read.
View Tutorial

Common Solidity Beginner Mistakes

Everyone makes mistakes, but some mistakes are more common than others.
View Tutorial

Solidity Beginner Projects

You now have enough knowledge to build any of the following projects. Knowledge comes by study, but skill comes with practice.
View Tutorial

Intermediate Topics

Token ERCs, Integers in Depth, and Others

If you already know some Solidity but are ready to move to the next level, this is the section to start.

Detecting if an address is a smart contract

This article describes three methods in Solidity for determining if an address is a smart contract:
View Tutorial

Solidity Function Selector

The function selector is a 4 byte id that Solidity uses to identify functions under the hood.
View Tutorial

ERC-721 design and security issues

ERC721 (or ERC-721) is the most widely used Ethereum standard for nonfungible tokens.
View Tutorial

ERC-1155

The ERC-1155 token can hold multiple fungible and non-fungible tokens in a single contract.
View Tutorial

ERC-4626

ERC4626 is a tokenized vault standard that uses ERC20 tokens to represent shares of some other asset.
View Tutorial

ERC-721 Enumerable

An Enumerable ERC721 is an ERC721 with added functionality that enables a smart contract to list all the NFTs an address owns.
View Tutorial

ERC-1363

ERC-1363 enables a smart contract to detect and respond to an incoming transfer of tokens.
View Tutorial

Uint256 Max Value

The uint256 max value can be obtained with type(uint256).max
View Tutorial

Signed Integers

Solidity signed integers enable using negative numbers in a smart contract. This article documents how they are used at the EVM level.
View Tutorial

Solidity Staticcall EIP-214

Staticcall is like a regular Ethereum call except that it reverts if a state change happens.
View Tutorial

OpenZeppelin Ownable2Step

The onlyOwner modifier is probably one of the most common patterns in Solidity.
View Tutorial

Testing internal functions

To test an internal solidity function, create a child contract that inherits from the contract being tested.
View Tutorial

Solidity events

Solidity events are the closest thing to a “print” or “console.log” statement in Ethereum.
View Tutorial

Solidity gasleft()

The purpose of this article is to describe the behavior of the solidity gasleft() function and its uses.
View Tutorial

Where to find reentrancy attacks

Reentrancy can only happen when your smart contract calls another smart contract via function call or sending ether.
View Tutorial

Generate a random number in Solidity

Randomness is tricky on the blockchain because the blockchain is deterministic, but randomness requires non-determinism (otherwise it becomes predictable).
View Tutorial

DeFi Primitives

Design Patterns Used Everywhere

Some building blocks and design patterns occur so frequently in DeFi applications that they are best studied directly. Don’t just read these tutorials, practice the problems at the end.

The staking algorithm of MasterChef and Synthetix

The MasterChef and Synthetix staking algorithms distribute a fixed reward pool among stakers according to their time-weighted contributions to a pool.
View Tutorial

Fixed Point Arithmetic

A fixed-point number is an integer that stores only the numerator of a fraction — while the denominator is implied.
View Tutorial

Flashloans

Flash loans are loans between smart contracts that must be repaid in the same transaction.
View Tutorial

Chainlink Price Feeds

Chainlink price oracles are smart contracts with public view functions that return the price of a particular asset denominated in USD.
View Tutorial

How DeFi Interest Rates Work

The intuitive way to track lender deposits is to record the amount of USDC they deposited and the time they deposited. Compound V3 does not do this.
View Tutorial

Uniswap V2 Walkthrough

The most forked DeFi protocol

Uniswap V2 is the most forked protocol in DeFi and has inspired several more. The Uniswap V2 Book is a line-by-line examination of the protocol.

Architecture

Uniswap is a DeFi app that enables traders to swap one token for another in a trustless manner.
View Tutorial

Price Impact of a Swap

his article explains how to determine the price settlement of a trading pair in an Automated Market Maker (AMM).
View Tutorial

Swap Function

Uniswap V2’s swap function is cleverly designed, but many devs find its logic counterintuitive the first time they encounter it.
View Tutorial

Mint and Burn Functions

The lifecycle of Uniswap V2 is someone mints LP tokens (supplies liquidity, i.e. tokens to the pool) for the first time.
View Tutorial

Protocol mintFee

Uniswap V2 was designed to collect 1/6th of the swap fees to the protocol. Since a swap fee is 0.3%, 1/6th of that is 0.05%, so 0.05% of every trade would go to the protocol.
View Tutorial

TWAP Oracle

Suppose we have 1 Ether and 2,000 USDC in a pool. This implies that the price of Ether is 2,000 USDC.
View Tutorial

UniswapV2Library

The Uniswap V2 Library simplifies some interactions with pair contracts and is used heavily by the Router contracts.
View Tutorial

Routers

The Router contracts provide a user-facing smart contract for safely minting and burning LP tokens (adding and removing liquidity)
View Tutorial

Building a Uniswap V2 Clone

It’s very educational to rebuild Uniswap v2 from scratch using modern Solidity (or Huff if you really want to do it in hard mode).
View Tutorial

Delegatecalls and Proxies

The web’s most comprehensive resource on upgradeable smart contracts

ABI Encoding

ABI encoding is the data format used for making function calls to smart contracts. It is also how smart contracts encode data when making calls to other smart contracts.
View Tutorial

EVM Storage

How storage variables work under the hood
View Tutorial

Low-level call in Solidity

A contract in Solidity can call other contracts via two methods: through the contract interface, which is considered a high-level call, or by using the call method, which is a low-level approach.
View Tutorial

Delegatecall

This article explains how delegatecall works in detail. The Ethereum Virtual Machine (EVM) offers four opcodes for making calls between contracts:
View Tutorial

ERC-1967

EIP 1967 is a standard for where to store information that proxy contracts need to execute.
View Tutorial

ERC-7201

ERC-7201 (formerly EIP-7201) is a standard for grouping storage variables together by a common identifier called a namespace.
View Tutorial

Transparent Upgradeable Proxy

The Transparent Upgradeable Proxy is a design pattern for upgrading a proxy while eliminating the possibility of a function selector clash.
View Tutorial

Beacon Proxies

EIP 1967 is a standard for where to store information that proxy contracts need to execute.
View Tutorial

Clones

EIP-1167, which is also referred to as the minimal proxy contract, is a commonly used solidity pattern for cheaply creating proxy clones.
View Tutorial

Metaproxy Clones

The minimal proxy standard allows us to parameterize the creation of the clone, but this requires an extra initialization transaction.
View Tutorial

Nodelegatecall

The nodelegatecall modifier prevents delegatecalls from being sent to a contract.
View Tutorial

Solidity Governance

How DAOs coordinate onchain

ERC-20 Snapshots

ERC20 Snapshot solves the problem of double voting.
View Tutorial

ERC-20 Votes

ERC20 Votes does not actually handle conducting the poll, it’s still a regular ERC20 token with snapshot and delegated voting abilities.
View Tutorial

Solidity Governance

The pattern of governance many DeFi applications follows is heavily inspired by Compound Finance’s implementation.
View Tutorial

Compound V3 Walkthrough

Explore the codebase of the most influential lending protocol

Compound V2 is the most forked lending protocol, but it is no longer used, so our walkthrough focuses on Compound V3. Nearly every modern lending protocol takes inspiration from Compound, so if you completely understand the codebase, you will easily be able to understand other DeFi lending protocols.

Architechture of Compound V3

Compound is one of the most significant lending protocols in DeFi, having inspired the design of nearly every lending protocol on several blockchains.
View Tutorial

Compound V3 Interest Per Second

The Compound V3 protocol measures interest on the scale of seconds. The Compound V3 frontend scales the number up to years for human friendliness.
View Tutorial

Principal vs Present Value and Interest Rate Indexes

The intuitive way to track lender deposits is to record the amount of USDC they deposited and the time they deposited.
View Tutorial

cUSDC V3 (Comet) as a non-standard Rebasing Token. CometExt.sol

The Compound V3 contract behaves like a rebasing ERC 20 token. A rebasing token is a token which has an algorithmically adjusted supply rather than a fixed one.
View Tutorial

Collateral, Liquidations, and Reserves in Compound V3

In this chapter we will examine the following topics about Compound V3: collateral valuation
View Tutorial

Compound V3 Rewards

Compound issues rewards in COMP tokens to lenders and borrowers in proportion to their share of the a market’s lending and borrowing.
View Tutorial

UniswapV2Library

The Uniswap V2 Library simplifies some interactions with pair contracts and is used heavily by the Router contracts.
View Tutorial

Routers

The Router contracts provide a user-facing smart contract for safely minting and burning LP tokens (adding and removing liquidity)
View Tutorial

Bulkers in Compound V3

The bulker contracts in Compound V3 are multicall-like contracts for batching several transactions.
View Tutorial

Gas Optimization

The Ultimate guide to improving smart contract efficiency

Ethereum access list transactions

An Ethereum access list transaction enables saving gas on cross-contract calls by declaring in advance which contract and storage slots will be accessed.
View Tutorial

Low Level Programming and Bytecode

What happens behind the Solidity compiler

Our Yul Course on Udemy

Smart contract metadata

When solidity generates the bytecode for the smart contract to be deployed, it appends metadata about the compilation at the end of the bytecode.
View Tutorial

Smart contract creation cost

Smart contract creation cost can be anywhere from $10 to $2,000 assuming Ether costs between $1,500 to $2,000.
View Tutorial

Smart contract creation code

This article explains what happens at the bytecode level when an Ethereum smart contract is constructed and how the constructor arguments are interpreted.
View Tutorial

EIP 150 and the 63/64 rule for gas

EIP-150, or Ethereum Improvement Proposal 150, is a protocol upgrade for the Ethereum blockchain.
View Tutorial

Testing Beyond Unit Testing

Tools to secure your smart contracts

Mistakes in smart contracts can be extremely costly. Therefore, employing as many tools as possible will maximize your chances of success against bugs and hackers.

Invariant Testing in Foundry

In this article, we will discuss invariants and how to perform an invariant test on solidity smart contracts using foundry test suites.
View Tutorial

Mutation Testing

Mutation testing is a method to check the quality of the test suite by intentionally introducing bugs into the code and ensuring the tests catch the bug.
View Tutorial

Advanced Topics in Solidity

For those further on in their Solidity journey

Second Preimage Attack

The second preimage attack in Merkle trees can happen when an intermediate node in a merkle tree is presented as a leaf.
View Tutorial

Precompiled smart contracts

Ethereum precompiles behave like smart contracts built into the Ethereum protocol. The nine precompiles live in addresses 0x01 to 0x09.
View Tutorial

RSA Signatures in Solidity

Creating a contract that gives certain addresses permissions goes by several names: airdrops, presale, whitelist, allowlist, and so forth.
View Tutorial

Tornado Cash Walkthrough

The most in-depth guide to the most significant mixer

How does tornado cash work

Tornado cash is a cryptocurrency smart contract mixer that enables users to deposit crypto with one address and withdraw with another wallet.
View Tutorial