solidity – Crowdsale with Existing Token

contract-designcontract-developmentsolidity

This might be a very general question, though I'd like if someone could clarify on how to within a crowdsale contract use an already deployed token contract with a fixed supply. I know how to create a mintable token internally from the crowdsale contract but I've never played around with an existing token though. Thank you

Best Answer

On your crowd sale contract, import the ERC20 interface and then code your smart contract to allow an ERC20 token to be set.

function setToken(address tokenAddress) {
        require(msg.sender == _ownerAddress);        
        _myToken = ERC20(tokenAddress);
    }

Now your crowd sale contract can call _myToken.balanceOf(this); to get the number of tokens it owns, and _mytoken.transfer(address, count); to distribute tokens according to whatever your desired crowdsale logic is.

So now all you need to do is transfer some or all of your minted tokens to the crowdsale contract address and you're ready to go.