0

With the standard open zeppelin ERC20 contracts, a fixed supply can be created by minting all of the new tokens to the contract creator. But this does not 'look good' and has the risk of the contract creator taking all the available balance. Is there a way to have a neutral address generated by the contract to hold the unallocated tokens? With functions then distributing the tokens as they are earned?

What is best practice for handling the risk of owner holding all the funds on contract initiation? Is it to create a fixed supply limit in the contract and _mint tokens within functions until that max level is hit? Or is there a better way to do it?

    constructor(uint256 initialSupply) public ERC20("SimpleToken", "SIM") {
        _mint(msg.sender, initialSupply);
    }

4
  • 1
    You can transfer the contract's ownership to the zero address. Sep 6, 2020 at 15:24
  • Thanks, I had not thought of that, is the contract then able to approve() and transferFrom() the zero address within functions?
    – Zakoff
    Sep 6, 2020 at 15:46
  • Just add owner = address(0); at the end of the constructor. Sep 6, 2020 at 15:47
  • Functions approve and transferFrom have nothing to do with ownership. Sep 6, 2020 at 15:48

1 Answer 1

1

Yes, first of all you need to create a contract that can distribute token on certain conditions.

Now you can actually deploy a erc20 contract and put the above contract address while minting. i.e

   constructor(uint256 initialSupply,contractAddress) public ERC20("SimpleToken", "SIM") {
    _mint(<contractAddress>, initialSupply);
}

If you dont want to pass contractaddress to constructor you can also deploy erc20 contract from your main contract

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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