2

I'm a little bit confused by the following code. Specifically, what the empty token contract does, and why it helps to create it. Is there no way to create an instance of a contract just by giving an address and then using the functions of that contract? Why do you need to create this empty code?

contract token { function give(address giveToAddress, uint amount) {} }

contract CrowdFund{

    token public rewardToken;

    function CrowdFund (
        string _name, 
        address _sendTo, 
        uint _durationInHours, 
        uint _priceInEther, 
        uint _minimum,
        token _rewardToken
    ){
        startTime = now;
        endTime = now + _durationInHours*60 minutes;
        name = _name;
        destination = _sendTo;
        tokenPriceInEther = _priceInEther*1 ether;
        minimum = minimumSend;
        rewardToken = _rewardToken;
    }

}
  • Hi there - can you include a link to where you copied this code from? Is it part of a tutorial? – Richard Horrocks Jul 21 '17 at 18:20
  • @RichardHorrocks yes it is here: ethereum.org/crowdsale – bGe Jul 21 '17 at 18:26
1

The page that this code is taken from (www.ethereum.org/crowdsale) has a section called Code Highlights that details what the token contract is for.

The below is taken from that page. Note the part in bold type.


The following line will instantiate a contract at a given address:

tokenReward = token(addressOfTokenUsedAsReward);

Notice that the contract understands what a token is because we defined it earlier by starting the code with:

contract token { function transfer(address receiver, uint amount){  } }

This doesn't fully describe how the contract works or all the functions it has, but describes only the ones this contract needs: a token is a contract with a transfer function, and we have one at this address.


So this tutorial gives you a framework only. It's up to the developer to flesh it out and add code in the way they want.

(And remember, you should never use code on the main network without knowing exactly what it does, lest you send real money to it.)

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.