Add default token supply to 0.5.0 solidity?

I have a smart contract which I wrote in solidity 0.5.0.
The issue I am having is that I can’t add default supply of token like 0.4.24 or other versions.
Can someone guide as what is the right way to add token supply in smart contract.
It is ERC-20 standard.

Thank you

1 Like

Hi @Raghav_Lyon,

Welcome to the community :wave:

To add an initial supply, you can call _mint in your token constructor and mint them to any required address such as the creator of the contract.
See the SimpleToken example:

The change was made in OpenZeppelin Contracts 2.0

All state variables are now private , which means that derived contracts cannot access them directly, but have to use getters. This is to increase encapsulation, to be able to reason better about the code. (#1197, #1265, #1267, #1269, #1270, #1268, #1281)

Feel free to ask all the questions that you need.

1 Like

Thank you Andrew.
I even used the same example which is given in above link. I placed every code in single .sol file and compiled using https://remix.ethereum.org.
I used https://www.myetherwallet.com to deploy into ropsten network. Everything is good but as usual my total supply is 0.

Thank you once and I will keep trying until I get it right.

1 Like

Hi again Andrew,

Once again I followed one of your earlier post Deploy a simple ERC20 token in Remix and I manage to deploy it. I could see the total supply of the tokens.

Now final question comes, if I have to add more supplies in existing tokens then what should I do? How can it be achieved?

Thank you

1 Like

Hi @Raghav_Lyon,

The following ERC20 token can be deployed using Remix.
You can mint additional tokens by calling mint from ERC20Mintable where the deployer of the contract has the MinterRole.

Token.sol

pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20Detailed.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20Mintable.sol";

contract Token is ERC20, ERC20Detailed, ERC20Mintable {

    constructor () public ERC20Detailed("Token", "TKN", 18) {
    }
}

Token deployed to Rinkeby: https://rinkeby.etherscan.io/token/0xe5fdabff287a46d97a001953cb17874d09cf7ba5

If you haven’t already, recommend reading the documentation on decimals

Thank you and it has solved my issue.
Next is continuous study for me :slight_smile: to get better understanding on ethereum contracts.

1 Like

Hi @Raghav_Lyon,

Feel free to ask all the questions that you need.

When you have some time it would be great to Introduce yourself here!