0Pricing
Web3 & DApp Development Fundamentals · Lesson

Token Extensions

Pausable, Burnable.

Token Extensions is a free Web3 & DApp Development Fundamentals lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web3 & DApp Development Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Extending Tokens

The base ERC-20 only handles transfers and approvals. OpenZeppelin provides extensions that add features by inheritance:

  • Pausable — freeze transfers in emergencies.
  • Burnable — let holders destroy tokens.
  • Capped — enforce a maximum supply.
  • Permit — gasless approvals via signatures.

Combining via Inheritance

You mix extensions by listing multiple base contracts:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; contract MyToken is ERC20, ERC20Burnable { constructor() ERC20("MyToken", "MTK") {} }
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

contract MyToken is ERC20, ERC20Burnable {
    constructor() ERC20("MyToken", "MTK") {}
}

Burnable Tokens

ERC20Burnable adds two functions:

  • burn(amount) — destroys the caller's own tokens.
  • burnFrom(account, amount) — burns from an account that approved you.

Burning reduces totalSupply, which can be used for deflationary mechanics.

// holder destroys their tokens
token.burn(ethers.parseEther("100"));

Pausable Tokens

ERC20Pausable lets an authorized account halt all transfers — useful during a security incident:

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract MyToken is ERC20, ERC20Pausable, Ownable { function pause() public onlyOwner { _pause(); } function unpause() public onlyOwner { _unpause(); } }
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, ERC20Pausable, Ownable {
    function pause() public onlyOwner { _pause(); }
    function unpause() public onlyOwner { _unpause(); }
}

How Pause Works

When paused, transfers revert with EnforcedPause. The Pausable extension hooks into the token's internal transfer logic, so transfer, transferFrom, mint, and burn are all blocked until unpause is called.

Use pausing sparingly — it centralizes control.

Resolving Function Conflicts

When two parents define the same internal hook, Solidity requires you to override it and specify the order:

function _update(address from, address to, uint256 value) internal override(ERC20, ERC20Pausable) { super._update(from, to, value); }

This tells the compiler how to linearize the inheritance.

function _update(address from, address to, uint256 value)
    internal override(ERC20, ERC20Pausable) {
    super._update(from, to, value);
}

Capped Supply

ERC20Capped enforces a hard maximum supply set at deployment:

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol"; contract MyToken is ERC20Capped { constructor() ERC20("MyToken", "MTK") ERC20Capped(1000000 * 10 ** 18) {} }

Any mint that would exceed the cap reverts.

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";

contract MyToken is ERC20Capped {
    constructor()
        ERC20("MyToken", "MTK")
        ERC20Capped(1000000 * 10 ** 18) {}
}

Gasless Approvals with Permit

ERC20Permit lets users approve spending with an off-chain signature instead of an on-chain approve transaction:

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; contract MyToken is ERC20, ERC20Permit { constructor() ERC20("MyToken", "MTK") ERC20Permit("MyToken") {} }

This improves UX by removing one transaction.

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract MyToken is ERC20, ERC20Permit {
    constructor()
        ERC20("MyToken", "MTK")
        ERC20Permit("MyToken") {}
}

Extensions for NFTs Too

ERC-721 has parallel extensions:

  • ERC721Enumerable — iterate over all tokens.
  • ERC721URIStorage — per-token metadata URIs.
  • ERC721Burnable / ERC721Pausable — same ideas as ERC-20.

The pattern of composing through inheritance is the same.

Compose Only What You Need

Each extension adds code, gas cost, and surface area. Include only the features your token actually requires:

  • Fewer extensions mean cheaper deployment and a smaller attack surface.
  • Document why each extension is present.

Votes Extension

ERC20Votes tracks historical voting power by snapshotting balances at each block, enabling on-chain governance:

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

Holders can delegate their votes, and proposals can query past voting power to prevent flash-loan manipulation.

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

Quick Check

Test your understanding of token extensions.

Recap

You learned to compose token features with extensions.

  • Extensions add behavior by multiple inheritance.
  • Burnable destroys tokens; Capped enforces max supply.
  • Pausable freezes transfers in emergencies.
  • Permit enables gasless, signature-based approvals.
  • Resolve hook conflicts by overriding (e.g. _update) and include only what you need.

Frequently asked questions

Is the “Token Extensions” lesson free?

Yes — the full text of “Token Extensions” is free to read here on the web, and the Web3 & DApp Development Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web3 & DApp Development Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Token Extensions”?

Pausable, Burnable. You practise Web3 & DApp Development Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Web3 & DApp Development Fundamentals?

No prior experience is required. Web3 & DApp Development Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Token Extensions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Web3 & DApp Development Fundamentals lesson?

Yes. Every Web3 & DApp Development Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why OpenZeppelin
  2. Access Control
  3. Token Extensions
  4. Upgradeable Contracts
← Back to Web3 & DApp Development Fundamentals