No initialSupply being added to contract

contract MyToken is ERC20, ERC20Detailed, Ownable{

            string memory _name,
            string memory _symbol,
            uint8 _decimals,
            uint256 _initialSupply
        ERC20Detailed(_name, _symbol, _decimals)
         _mint(msg.sender, _initialSupply);

For some reason, I’ve spent all day on this. I give assign my token the supply in the deployment.js file but it doesnt seem to show up when I check the balance through metamask. Could someone put me in the right direction? First time setting up a ERC20 so I am quite new to all this.

1 Like

Hi @Mark19,

Welcome to the community :wave:

Can you share your deployment.js?

If you are deploying to a public testnet, then I suggest you look at the holders on Etherscan to see how many tokens the account you are using with MetaMask has, otherwise use truffle console.

It could be an issue with the amount of tokens and decimals. Where the number of tokens is so small that MetaMask displays as zero. I suggest reading the documentation on decimals:

I suggest starting with the initial supply hardcoded in the constructor so that you know that there aren’t any issues with decimals. I use SimpleToken.sol for this purpose.


pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.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.
contract SimpleToken is ERC20, ERC20Detailed {
    uint8 public constant DECIMALS = 18;
    uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(DECIMALS));

     * @dev Constructor that gives msg.sender all of existing tokens.
    constructor () public ERC20Detailed("SimpleToken", "SIM", DECIMALS) {
        _mint(msg.sender, INITIAL_SUPPLY);


const SimpleToken = artifacts.require("SimpleToken");

module.exports = function(deployer) {


Hi abcoathup,

Thanks for the reply. This is my deploy.js. By the looks of it, I’m giving my ERC20 the attributes in the wrong file but was following along with a tutorial that done it this way.

const MyToken = artifacts.require("MyToken");

module.exports =  async function(deployer) {
  const _name = "My Token";
  const _symbol = "MYTO";
  const _decimals = 1;
  const _totalSupply = 5000;

  await deployer.deploy(MyToken, _name, _symbol, _decimals, _totalSupply);
  const deployedToken = await MyToken.deployed();
1 Like

Hi @Mark19,

Your token code and migrations script are fine. I was able to deploy to ganache-cli and add the token to MetaMask.

I also deployed to Ropsten testnet:

I have put some high level instructions below, but let me know if you need more detail:

Using ganache-cli, run ganache and copy the private key for account 0 e.g. 0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d

$ ganache-cli -d
Ganache CLI v6.6.0 (ganache-core: 2.7.0)

Available Accounts
(0) 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 (100 ETH)
(1) 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0 (100 ETH)
(2) 0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b (100 ETH)
(3) 0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d (100 ETH)
(4) 0xd03ea8624C8C5987235048901fB614fDcA89b117 (100 ETH)
(5) 0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC (100 ETH)
(6) 0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9 (100 ETH)
(7) 0x28a8746e75304c0780E011BEd21C72cD78cd535E (100 ETH)
(8) 0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E (100 ETH)
(9) 0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e (100 ETH)

Private Keys
(0) 0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
(1) 0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1
(2) 0x6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c
(3) 0x646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913
(4) 0xadd53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743
(5) 0x395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd
(6) 0xe485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52
(7) 0xa453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3
(8) 0x829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4
(9) 0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773

In MetaMask, click import account and paste in the private key.
Change the network in MetaMask to localhost:8545.

Deploy the token

$ npx truffle migrate --network development


   Deploying 'MyToken'
   > transaction hash:    0x5deffe8ed4a7d591472a29081a60b6fc211374cb4f7a43c3d83999c70ff82bc1
   > Blocks: 0            Seconds: 0
   > contract address:    0xCfEB869F69431e42cdB54A4F4f105C19C080A601

Copy the contract address for the token.

In MetaMask, in the menu for your ganache account press add token, and change to custom token and paste in the contract address. You will see 500 MyToken’s with 1 decimal place.

1 Like

Hi @Mark19,

I wanted to check if you were able to view the token balance in MetaMask?

Hi, Yeah, got it all sorted. I didn’t even know you could deploy a smart contract from remix but hey, eveydays a school day so they say :stuck_out_tongue: Thank you so much for your help, really appreciate it :slight_smile:

1 Like

Hi @mark19,

Glad I could help. Feel free to ask all the questions that you need.

You can also deploy a simple token using Remix:

1 Like

A post was split to a new topic: Add account to MetaMask