0

Is it possible to deploy the Token contract (T) & CrowdSale contract (S) separately and still be possible to access (T)'s modifier protected methods from (S).

Code of (T)

 contract Token {
    function mint(address _to, uint256 _amount) onlyOwner canMint returns (bool) {
     totalSupply = totalSupply.add(_amount);
     balances[_to] = balances[_to].add(_amount);
     Mint(_to, _amount);
     return true;
 }

Code of (S)

contract SellToken {
  TokenInstance instance;
  function SellToken(address _address) {
    instance = TokenInstance(_address);
  }

  function () payable { 
    uint256 weiAmount = msg.value;

    // calculate token amount to be created
    uint256 tokens = weiAmount.mul(rate);

    // update state
    weiRaised = weiRaised.add(weiAmount);

    instance.mint(beneficiary, tokens);
  }

}

For some reason, when i'm trying to send ether to (B) I get the following error

Transaction cannot be processed

EDIT: I also tried the method of having an Abstract interface but that didn't seem to have much luck either (Ref: Stack exchange Post)

Abstract Interface

contract TokenAbstractInterface {
    function mint(address _to, uint256 _amount) returns (bool);
    function finishMinting() returns (bool);
}

Modified Code of (S)

contract SellToken {
  TokenAbstractInterface instance;
  function SellToken(address _address) {
    instance = TokenAbstractInterface(_address);
  }

  function () payable { 
    uint256 weiAmount = msg.value;

    // calculate token amount to be created
    uint256 tokens = weiAmount.mul(rate);

    // update state
    weiRaised = weiRaised.add(weiAmount);

    instance.mint(beneficiary, tokens);
  }

}
1

Without the full code is hard to be sure. But the function mint in Token as onlyOwner modifier.

function mint(address _to, uint256 _amount) onlyOwner canMint returns (bool)

This usually implies that only the owner of the token can call mint function, if you want.

If you want to mint token from SellToken you have to set SellToken as the owner of Token contract.

  • Yes you were right on this. I had to transfer the Token's ownership to the Smart contract. I also had to add a method to retransfer the Token ownership from the Smart contract to any other account as to not get locked out when the crowdsale gets over. – Sam Sep 27 '17 at 20:35

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.