0

When uploading an ERC20 token for an ICO, how does one program the ICO token sale? Is it done in the same contract? It seems to be judging by existing sales that you send ether to a contract address, but what function does this trigger?

3

Usually, the raising of funds through a crowdsale is achieved through a different contract to the one implementing the ERC20 standards - this separation of concerns is a good software development practice.

Open Zeppelin is an excellent project, establishing best practices for Smart Contracts, creating secure code and a reputation for their code being used in a large number of high profile projects - I would recommend looking at some examples of approaches to implementing a crowdsale contract.

It seems to be judging by existing sales that you send ether to a contact address, but what function does this trigger?

Ultimately, this depends on design decisions made about the behavior of the token and the way that the crowdsale contract works.

One practice, it is achieved by calling either the transfer or transferFrom functions defined in the ERC20 standards e.g. TokenMarketNet's AllocatedCrowdsale


 /**
   * Transfer tokens from approve() pool to the buyer.
   *
   * Use approve() given to this crowdsale to distribute the tokens.
   */
  function assignTokens(address receiver, uint tokenAmount) private {
    if(!token.transferFrom(beneficiary, receiver, tokenAmount)) throw;
  }
}

However, you can see that OpenZeppelin's crowdsale contract instead calls a mint function defined on the Token contract that isn't defined as part of the ERC20 specifications:


  // low level token purchase function
  function buyTokens(address beneficiary) public payable {
    require(beneficiary != address(0));
    require(validPurchase());
    uint256 weiAmount = msg.value;
    ....
    token.mint(beneficiary, tokens);
    TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);
    forwardFunds();
  }

  • I've looked at the OpenZeppelin crowdsale contract you linked to. If I understand correctly, this contract deploys a token on its own which supports a mint function. How does one specify the deployed token's supply and other constructor parameters here? – Saeid Hashemi Nov 5 '17 at 23:17
0

Saeid Hashemi

truffle uses a file 2_deploy_contracts.js file to define the variables in the contract. If you install truffle on linux, it comes with an example coin/crowdsale contract you can study. Look for the 2_deploy_contracts.js file and look at the structure.

Truffle combines multiple contracts into one deployment. That is why you do not see all the information you are looking for.

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.