6

I have deployed Standard token contract using mist. Now I want to create interface functions for the deployed contract.

contract MyToken {
    function mint(address _to, uint256 _amount) onlyOwner returns (bool);
}

contract NewContract {

    Mytoken token;

    uint256 public rate;

    function NewContract(uint256 _rate){
        rate = _rate;
    }

    function () payable {
        token.mint(msg.sender, msg.value);
    }
}

First issue is I can't create interface for those functions that have some custom modifiers attached i.e onlyOwner. If I remove the modifer onlyOwner, I am able to deploy using mist, but when I transfer some amount to this contract it throws callback contain no result Gas required exceeds limit.

3

Recommended way is to have mint() function in token contract and I don't see any issue with that.

First part of your question: You can call onlyOwner function by preserving msg.sender and can be achieved by using delegatecall.

Second Part: Your code is not working even after removing modifier because you have to initialize the object of Mytoken with the address of the token contract that is already deployed on blockchain like:

    contract MyToken {
        function mint(address _to, uint256 _amount) returns (bool);
    }
    contract NewContract {

        Mytoken token;

        uint256 public rate;

        function NewContract(uint256 _rate,address _tokenAddress){
           token = Mytoken(_tokenAddress);
           rate = _rate;
        }
        function () payable {
            token.mint(msg.sender, msg.value);
        }
    }  

Above code will work if you remove onlyOwner modifier from mint() function.

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.