I am learning to develop smart contract using Solidity. Currently, I am working and test the feature of following crowdsale contract.


This contract constructor has three different values.

  1. rate
  2. wallet address
  3. token address

I am confused about the first one that is "rate". what value should i have to pass here ?

for example, I want to sell 1 token at cost of 1 ether then what should i pass here ?


As you can see the function

function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {
    return _weiAmount.mul(rate);

It states that for 1 wei, the no of tokens will be 1*rate.

for example, I want to sell 1 token at cost of 1 ether then what should i pass here ?

This depends on number of decimals in your toke contract. For eg, if you have 18 decimals,then

token = wei * rate

1 Token = 1 ether * rate

10 ^18 token = 10 ^18 wei * rate

=> rate = 1
  • I have deployed the crowdsale contract with my fixed supply token but it gives an exection. – Sandeep Jun 22 '18 at 7:29
  • my fixed supply has 18 decimal – Sandeep Jun 22 '18 at 7:30
  • exception is constructor should be payable if you send the value – Sandeep Jun 22 '18 at 7:31
  • You need to make any function that accepts ether payable – Prashant Prabhakar Singh Jun 22 '18 at 10:58
  • you can see in my crowdsale contract there is a function name buyTokens() that is payable. – Sandeep Jun 23 '18 at 5:24


Wei to Ether

Wei is the 18 digits that go into an Ether


Rate is explained in the OpenZeppelin Contracts Crowdsale documentation: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate

You can also ask questions about how to use OpenZeppelin Contracts in the Community Forum

Disclosure: I am the the Community Manager at OpenZeppelin

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.