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
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.
If the token contract has an owner and a function to transfer ownership to another address, and a minting function which can only be called by the owner of the contract, then it is possible by setting the token owner to be the ICO contract.
Did you manage to make it work? In the green marked answer I read: "import the ERC20 interface"; does this mean to import the ABI interface or the Solidity code of the already deployed token contract?
TokenMarket ICO contains an out of the box token sale smart contract AllocatedCrowdsale
.
You put tokens for sale using EIP-20 approve()
.
https://github.com/TokenMarketNet/ico/blob/master/crowdsales/allocated-token-sale-example.yml
-
-
1They are covered here: ico.readthedocs.io/en/latest/commands.html#deploy-contracts – Mikko Ohtamaa Nov 27 '17 at 21:06