Intermediate

ERC-20 Token Implementation — Hands-on lab

Create a standard token.

Developer Intermediate
6/8 — ERC-20 Token Implementation — Hands-on lab

ChecklistThis lab is your repeatable checklist for shipping a trustworthy ERC-20. Stay disciplined: write tests as you go and verify on an explorer so you see exactly what integrators will see.

FocusFocus on approvals, events, and supply math. Treat this repo as your starter kit for future tokens.

Assertions to bake into tests
balance_from′ = balance_from − amount
balance_to′ = balance_to + amount
allowance′ = allowance − amount
totalSupply′ = totalSupply + minted − burned

Make these invariants first-class so regressions are caught immediately.

Steps
  1. Init a Hardhat/Foundry project;:Install @openzeppelin/contracts; set decimals intentionally (18 unless you have a reason).
  2. Implement an ERC20 with:Constructor name/symbol; add Ownable or AccessControl and gate mint/burn behind roles.
  3. Write tests for mint,:Transfer, approve/transferFrom, burn, and event emissions; include allowance decrease and revoke tests. Keep the formula card above nearby while you assert the math.
  4. Simulate an “infinite approval”:Flow, then show how to revoke or reduce an allowance and assert the new value. Confirm allowance′ = allowance − amount when it is not infinite.
  5. Deploy to a testnet:Verify in an explorer, exercise approve + transferFrom, and watch allowances change in the explorer UI. Confirm your supply and balance invariants still hold after live interactions.
  6. Document supply rules and:Admin keys in your README so integrators know who can mint, pause, or burn.
← Previous section
Next section →