ERC-20 Token Implementation — Key concepts
Create a standard token.
Surface vs impactThe ERC-20 surface is small; the implications are large. Know what is mandatory vs optional, when to emit events, how allowances mutate, and why decimals matter for UX. The standard is a contract with every wallet, explorer, and DEX.
Bitcoin seems to be a very promising idea. I like the idea of basing security on the assumption that the CPU power of honest participants outweighs that of the attacker.
GuardrailsInternalize this to avoid “why did my allowance drain?” and “why is totalSupply off?” tickets. Treat these as guardrails before you touch code or merge a PR. Good mental models beat creative shortcuts and speed up audits.
Balance updatesTransfers must keep holder math consistent.
balance_to′ = balance_to + amount
Holder balances change, but the sum for these two holders stays constant; emit Transfer for visibility.
Allowance flowApprovals decay as they are used.
Unless you intentionally support “infinite” approvals, decrement and emit Approval so indexers match the new value.
Supply changesMinting and burning must track total supply.
Role-gate who can mint/burn and assert this invariant in tests.
- What “implementing an ERC-20”:Really means in practice conforming to a standard interface and emitting events consistently.
- Minting vs burning and:Their impact on total supply how to grow, shrink, and report supply without drifting.
- Allowance / approve /:TransferFrom flow and common pitfalls race conditions, unlimited approvals, and revocation patterns.
- OpenZeppelin extension patterns you:Should reuse Ownable/AccessControl, Pausable, and burnable/mintable modules.
- Deployment + verification basics:Constructor args, decimals choice, and verifying source so integrators trust the code.
- Events as integration glue:Transfer and Approval must fire on every change or indexers and wallets misbehave.
- Roles and ownership:Who can mint, pause, or burn—and how you rotate that power safely.
- Decimals and UX:Why choosing 18 by default keeps tooling happy unless you have a strong reason to diverge.
- Tests as specification:Unit tests for supply changes, allowances, and events double as living documentation for integrators.
- Gas and allowances:Why spending from an allowance still charges the spender’s EOA and must be considered in UX.