Crowdsale Contract – How to Mint Tokens in Another Token Contract

erc-20icoopenzeppelintokens

I'm trying to create a crowdsale contract with open-zeppelin. I'm using SampleCrowdsale.sol. I believe the following line of code creates a token contract and mints the token upon receiving ether.

function createTokenContract() internal returns (MintableToken) {
    return new SampleCrowdsaleToken();
  }

However, I rather want the crowdsale contract to mint a token in another mintable token contract. Is there any way the crowdsale contract can interact with an external token contract? Any suggestion or code snippet would be really helpful.

Best Answer

Yes what you need to do is first create your token in a separate contract. Then when you create your crowdsale you pass in the constructor the address of your token.

This is a sample taken from the Ethereum Crowdfund your idea

pragma solidity ^0.4.16;

interface token {
    function mintToken(address receiver, uint amount);
}

contract Crowdsale {
    token public tokenReward;

    /**
     * Constrctor function
     */
    function Crowdsale(
        address addressOfTokenUsedAsReward
    ) {
        tokenReward = token(addressOfTokenUsedAsReward);
    }
}
Related Topic