Vishwas1 / hid

Hypersign ERC20 token contract
0 stars 1 forks source link

Fixed supply contract #1

Open vikramIde opened 3 years ago

vikramIde commented 3 years ago

https://docs.openzeppelin.com/contracts/3.x/erc20-supply

vikramIde commented 3 years ago

v1 version

contract ERC20FixedSupply is ERC20 {
    constructor() public {
        totalSupply += 1000;
        balances[msg.sender] += 1000;
    }
}

v2 version

contract ERC20FixedSupply is ERC20 {
    constructor() public ERC20("Fixed", "FIX") {
        _mint(msg.sender, 1000);
    }
}

Starting with Contracts v2 this pattern is not only discouraged, but disallowed. The variables totalSupply and balances are now private implementation details of ERC20, and you can’t directly write to them. Instead, there is an internal _mint function that will do exactly this: