iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up
Next »

Summary

Wrapping up the Web3 track with what you can ship and where to go next.

What you learned + Foundry invariant test

EXAMPLE
# Web3 summary

You can now:

- Read and write Solidity with storage layout discipline
- Understand ERC-20, ERC-721, ERC-1155 mechanics
- Write Foundry tests including fuzz + invariant
- Avoid reentrancy via checks-effects-interactions
- Use OpenZeppelin contracts where possible
- Deploy to testnets + verify on Etherscan
- Wire frontends with viem + wagmi
- Index events with The Graph, Ponder, or Goldsky

# Your next step - a Foundry invariant test

// test/Vault.invariant.t.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import 'forge-std/Test.sol';
import { Vault } from '../src/Vault.sol';

contract VaultInvariantTest is Test {
    Vault vault;

    function setUp() public {
        vault = new Vault();
        targetContract(address(vault));
    }

    // Total deposited must equal sum of balances - always.
    function invariant_TotalEqualsSumOfBalances() public {
        // Foundry calls random functions on vault with random args; this must hold.
        assertEq(vault.totalDeposited(), vault.sumOfBalances());
    }
}

Why it matters

Audit before you deploy. Most exploited contracts had clean tests but were not threat-modeled - read recent post-mortems before you ship anything that holds value.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// Next: account abstraction (ERC-4337), zk-circuits, MEV-aware design, app chains.
Try it Yourself »

Discussion

Loading…

Next »