Learn Solidity

The Ultimate Solidity Course

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.

ALT TITLE

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).

ALT TITLE

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

3. Set up Foundry

The Most popular development framework in 2024

4. Arithmetic

A quick overview of doing math in Solidity

5. If Statements

A quick lesson on conditional operators

6. For loops

Syntax for iterative operators

7. Introduction to arrays and strings

Data types of unbounded size

8. Nested Arrays

2D and 3D data types

9. Storage Variables

Using a “database in Web3”

10. Arrays in Storage

Persistent lists

11. Mappings

Persistent lists

12. Nested Mappings

Persistent hash maps with multiple levels

13. msg.sender and address(this)

Determining which wallet is calling the smart contract

14. Constructor

Configuring the smart contract on deployment

15. Require

Protecting smart contracts from malicious parameters

16. ERC-20 Tokens

An introduction to the most fundamental building block of DeFi

17. Tuples

Batching values together

18. Application binary interface (ABI encoding)

Solidity’s binary encoding format of choice

19. Contracts calling other contracts

Learn how composability works in Solidity

21. Payable functions

Transferring Ether with function calls

22. Receive

How smart contract can receive ETH transactions

23. Block.timestamp and block.number

What is the date and time today?

24. Emitting Events

Leaving an audit trail in smart contracts

25. Inheritance

Organizing code in large smart contracts

26. Modifiers

Add re-useable functionality to Solidity function

27. Immutable variables

Write-once variables

28. Constants

How to avoid “magic numbers”

29. Deploying an ERC-721 to OpenSea

Share your NFT with the world

30. Launch and verify and NFT with Foundry

Open source the code of an NFT

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

Convenient keywords for dealing with large numbers

32. Structs

How to keep data in groups

33. Strings

Concatenation, UTF-8 encoding, and more

34. Unit Testing in Solidity

How to write professional unit tests in Foundry

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.

ALT TITLE

Professional Solidity Style Guide

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

ALT TITLE

Common Solidity Beginner Mistakes

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

ALT TITLE

Solidity Beginner Projects

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

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.

ALT TITLE

Detecting if an address is a smart contract

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

ALT TITLE

Solidity Function Selector

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

ALT TITLE

ERC-721 design and security issues

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

ALT TITLE

ERC-4626

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

ALT TITLE

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.

ALT TITLE

ERC-1363

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

ALT TITLE

Uint256 Max Value

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

ALT TITLE

Signed Integers

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

ALT TITLE

Solidity Staticcall EIP-214

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

ALT TITLE

OpenZeppelin Ownable2Step

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

ALT TITLE

Testing internal functions

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

ALT TITLE

Solidity events

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

ALT TITLE

Solidity gasleft()

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

ALT TITLE

Where to find reentrancy attacks

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

ALT TITLE

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).

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.

ALT TITLE

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.

ALT TITLE

Fixed Point Arithmetic

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

ALT TITLE

Flashloans

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

ALT TITLE

Chainlink Price Feeds

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

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

Architecture

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

ALT TITLE

Price Impact of a Swap

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

ALT TITLE

Swap Function

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

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

UniswapV2Library

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

ALT TITLE

Routers

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

ALT TITLE

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).

Delegatecalls and Proxies

The web’s most comprehensive resource on upgradeable smart contracts

ALT TITLE

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.

ALT TITLE

EVM Storage

How storage variables work under the hood

ALT TITLE

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.

ALT TITLE

Delegatecall

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

ALT TITLE

ERC-1967

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

ALT TITLE

ERC-7201

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

ALT TITLE

Transparent Upgradeable Proxy

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

ALT TITLE

Beacon Proxies

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

ALT TITLE

Clones

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

ALT TITLE

Metaproxy Clones

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

ALT TITLE

Nodelegatecall

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

Solidity Governance

How DAOs coordinate onchain

ALT TITLE

ERC-20 Snapshots

ERC20 Snapshot solves the problem of double voting.

ALT TITLE

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.

ALT TITLE

Solidity Governance

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

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

Collateral, Liquidations, and Reserves in Compound V3

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

ALT TITLE

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.

ALT TITLE

UniswapV2Library

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

ALT TITLE

Routers

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

ALT TITLE

Bulkers in Compound V3

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

Gas Optimization

The Ultimate guide to improving smart contract efficiency

ALT TITLE

Our Gas Optimization Course on Udemy

The OG gas optimization course.

ALT TITLE

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.

ALT TITLE

Ultimate List of Solidity Gas Optimization Tricks

Over 80 gas optimization tips and tricks.

Low Level Programming and Bytecode

What happens behind the Solidity compiler

Our Yul Course on Udemy

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

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.

ALT TITLE

EIP 150 and the 63/64 rule for gas

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

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.

ALT TITLE

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.

ALT TITLE

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.

Advanced Topics in Solidity

For those further on in their Solidity journey

ALT TITLE

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.

ALT TITLE

Precompiled smart contracts

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

ALT TITLE

RSA Signatures in Solidity

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

Tornado Cash Walkthrough

The most in-depth guide to the most significant mixer

ALT TITLE

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.