0

can I get an explanation about this section of the smart contract especially the supply function. and what does

 totalSupply = _supply * 10**_decimals;

means? I will like to created a mintable token with maximum supply capped

contract CoinToken is PausableToken {
string public name;
string public symbol;
uint public decimals;
uint public supply_cap;
event Mint(address indexed from, address indexed to, uint256 value);
event Burn(address indexed burner, uint256 value);


constructor(string memory _name, string memory _symbol, uint256 _decimals, uint256 _supply, address tokenOwner) public {
    name = _name;
    symbol = _symbol;
    decimals = _decimals;
    totalSupply = _supply * 10**_decimals;
    balances[tokenOwner] = totalSupply;
    owner = tokenOwner;
    
    emit Transfer(address(0), tokenOwner, totalSupply);
}

function burn(uint256 _value) public {
    _burn(msg.sender, _value);
}

function _burn(address _who, uint256 _value) internal {
    require(_value <= balances[_who]);
    balances[_who] = balances[_who].sub(_value);
    totalSupply = totalSupply.sub(_value);
    emit Burn(_who, _value);
    emit Transfer(_who, address(0), _value);
}

function mint(address account, uint256 amount) onlyOwner public {

    totalSupply = totalSupply.add(amount);
    balances[account] = balances[account].add(amount);
    emit Mint(address(0), account, amount);
    emit Transfer(address(0), account, amount);
}

1 Answer 1

1

The totalSupply saves the supply taking the decimals into account. The ** operator means power to the following number, is like saying 10^_decimals.

Lets say you have a _supply = 1 with _decimals = 0, the total supply would be 1 * 10^0 = 1*1 = 1.

That would mean that if you mint 1 means 1 tokens.

There is no getting lost with that, but let's say we support 2 decimals:

_supply = 1;
_decimals = 2;
totalSupply = 1*(10^2);
totalSupply = 100;

That would mean that if you mint 50 means 0.5 tokens. Or if you mint 100 its 1 token.

1
  • Thanks Julissa, that means, if I created a token with decimal as 2, i can have 0.01 as the minimum right?
    – Csmart
    Feb 7 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.