Create Your Own Token: ERC-20 Standard, OpenZeppelin Implementation, Minting, Burning and Approvals

Blockchain Developer 60 min min read Updated: Nov 17, 2026 Intermediate
Create Your Own Token: ERC-20 Standard, OpenZeppelin Implementation, Minting, Burning and Approvals
Intermediate Topic 2 of 3

What Is a Token?

A token is a balance sheet kept by a smart contract. The contract stores who owns how many units. ERC-20 is the standard for fungible tokens, where every unit is identical and interchangeable (like rupees or dollars).

ERC-20 Interface

FunctionPurpose
totalSupply()Total tokens in existence
balanceOf(owner)Balance of an address
transfer(to, amount)Send tokens from caller
approve(spender, amount)Allow another address to spend your tokens
allowance(owner, spender)How much the spender may still use
transferFrom(from, to, amount)Spender moves tokens on behalf of owner

Events: Transfer and Approval. Wallets and exchanges rely on these standard names.

Decimals

  • Tokens have no decimal type, so 18 decimals is the usual convention
  • A balance of 1000000000000000000 with 18 decimals is 1.0 token
  • Wallets display the number divided by 10^decimals

Build It With OpenZeppelin

solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract CampusCoin is ERC20, ERC20Burnable, Ownable { constructor(uint256 initialSupply) ERC20("Campus Coin", "CAMP") Ownable(msg.sender) { _mint(msg.sender, initialSupply * 10 ** decimals()); } function mint(address to, uint256 amount) external onlyOwner { _mint(to, amount); } }
  • _mint creates tokens. Here the deployer gets the first supply
  • Only the owner can mint more. Think about this carefully: unlimited owner minting is a trust risk
  • ERC20Burnable lets holders destroy their own tokens

The Approve and TransferFrom Flow

A decentralized exchange cannot take tokens from your wallet without permission. The flow is:

  1. You call approve(exchange, 100). This allows the exchange contract to pull up to 100 tokens
  2. The exchange calls transferFrom(you, pool, 100) when you trade
  3. The allowance goes down by the amount used
Unlimited approvals Some apps ask for unlimited approval. If that contract is hacked, your tokens can be drained. Approve only what you need and revoke old approvals.

Test in Remix

  1. Deploy with 1000 as initialSupply
  2. Call balanceOf for your account. You should see 1000 followed by 18 zeros
  3. Call transfer to another account. Check both balances
  4. Call approve from account 1 for account 2, then transferFrom from account 2

Design Questions Before Launch

  • Fixed or mintable supply?
  • Who holds the owner key? Use multisig for real projects
  • Do you need pausing, taxes or blocklists? Each adds risk
  • Has the contract been tested and audited?

Practice

  1. Create your own token with a fixed supply and no mint function
  2. Explain approve and transferFrom to a friend
  3. Why do tokens use 18 decimals?

Conclusion

ERC-20 is the fungible token standard. Build with OpenZeppelin, think carefully about minting power, and understand approve plus transferFrom for safe interactions.

Quick Summary: token; interface; decimals; build; approve flow; test; design.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators