2

I have a simple ERC20 contract which is ERC20Detailed, ERC20Mintable and Ownable. On deployment I want:

  1. Add Minter to a new account, passed in the argument
  2. Remove deployer from Minter role
  3. Transfer Ownership to a new account, passed in the argument

Same actions I have declared in another function called transferRights()

The problem is that I am getting "Gas estimation failed error", which isn't because I don't have enough gas, but there might be a bug in the code. If I remove first two (addMinter, renounceMinter) actions, then it's all good (No warning).

I have deployed this contract on Ropsten, where I was getting same error in the beginning, but by commenting first two actions and adding them again transaction went through without any warning and Contract works as it supposed to be.

pragma solidity ^0.5.0;

import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";


contract MyToken is ERC20Detailed, ERC20Mintable, Ownable {    

    uint256 private msgCount;
    address constant ETHER = address(0);
    mapping(uint256 => string) private message;

    constructor(string memory name, string memory symbol, uint8 decimals, address _newOwner) ERC20Detailed(name, symbol, decimals) public {
        addMinter(_newOwner);
        renounceMinter();
        transferOwnership(_newOwner);
    }

    function doMint(uint256 _amount, address _beneficiary1, address _beneficiary2, address _beneficiary3) public onlyOwner {
        require (_amount >= 0);
        require(_beneficiary1 != ETHER && _beneficiary2 != ETHER && _beneficiary3 != ETHER);
        require(mint(_beneficiary1, _amount.mul(20).div(100)));
        require(mint(_beneficiary2, _amount.mul(30).div(100)));
        require(mint(_beneficiary3, _amount.mul(50).div(100)));
    }

    function setMessage(string memory _message) public onlyOwner {
        message[msgCount] = _message;
        msgCount = msgCount.add(1);
    }

    function readMessage(uint256 _msgId) public view returns(string memory) {
        return message[_msgId];
    }

    function transferRights(address _newOwner) public onlyOwner {
        addMinter(_newOwner);
        renounceMinter();
        transferOwnership(_newOwner);
    }
}

I can still send a transaction and deploy I guess (as mentioned above I did it on testnet), even though it is saying "The transaction execution will likely fail", but I want to make sure that code is bug free. Any feedback would be greatly appreciated. Thanks!

UPDATE Problem found! In the constructor I was passing the same account address as I was using for deploying. Thus, it resulted adding the Minter role to myself, which I already had.

Gio
  • 73
  • 2
  • 13
  • Problem found! In the constructor I was passing the same account address as I was using for deploying. Thus, it resulted adding the Minter role to myself, which I already had. – Gio Sep 26 '19 at 10:50
  • You should update your question with the answer. Put it on the top of the question or answer it below. – Zulhilmi Zainudin Sep 28 '19 at 12:35

0 Answers0