Simple ERC20 token example

Simple ERC20 token example.

:warning: The following code has not been tested nor audited.
Seek appropriate advice on regulatory compliance and your solution should have appropriate testing and auditing

Recommend reading: Points to consider when creating a fungible token (ERC20, ERC777)

:exclamation: There is an open issue to add a fixed supply ERC20 preset:

This example smart contract merely sets a name, symbol and intial supply. All tokens are pre-assigned to the creator using the internal mint function.


// contracts/SimpleToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;

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

 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` functions.
 * Based on
contract SimpleToken is ERC20 {
     * @dev Constructor that gives msg.sender all of existing tokens.
        string memory name,
        string memory symbol,
        uint256 initialSupply
    ) public ERC20(name, symbol) {
        _mint(msg.sender, initialSupply);

Migration (Truffle)


// migrations/2_deploy.js
const SimpleToken = artifacts.require('SimpleToken');

module.exports = async function (deployer) {
  await deployer.deploy(SimpleToken, 'SimpleToken', 'SIM', '10000000000000000000000');



// test/SimpleToken.test.js
// SPDX-License-Identifier: MIT

// Based on

const { expect } = require('chai');

// Import utilities from Test Helpers
const { BN, expectEvent, expectRevert, constants } = require('@openzeppelin/test-helpers');

// Load compiled artifacts
const SimpleToken = artifacts.require('SimpleToken');

// Start test block
contract('SimpleToken', function ([ creator, other ]) {

  const NAME = 'SimpleToken';
  const SYMBOL = 'SIM';
  const TOTAL_SUPPLY = new BN('10000000000000000000000');

  beforeEach(async function () {
    this.token = await, SYMBOL, TOTAL_SUPPLY, { from: creator });

  it('retrieve returns a value previously stored', async function () {
    // Use large integer comparisons
    expect(await this.token.totalSupply());

  it('has a name', async function () {

  it('has a symbol', async function () {
    expect(await this.token.symbol());

  it('assigns the initial total supply to the creator', async function () {
    expect(await this.token.balanceOf(creator));


If you are looking for a crowdsale example, see: Simple ERC20 Crowdsale.


@abcoathup this is great! I actually managed to successfully write 5 tests last night after 10 painful days of mental brincsmanship. Your example is extremely helpul – i will take a good look at these. Thank you so much!!

1 Like