A basic question on how zepplin solidity code calculates token rates. The code comments say

// how many token units a buyer gets per wei

 uint256 public rate;

however we cannot get it to serve back 1000 tokens per ETH when we pass an ammount as the rate into;

function Crowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet) {
    require(_startTime >= now);
    require(_endTime >= _startTime);
    require(_rate > 0);
    require(_wallet != address(0));

    token = createTokenContract();
    startTime = _startTime;
    endTime = _endTime;
    rate = _rate;
    wallet = _wallet;

the rate is used in;

   uint256 weiAmount = msg.value;

    // calculate token amount to be created
    uint256 tokens = weiAmount.mul(rate);

Again, whatever rate we send in, high or low does not come out at 1,000 tokens per eth.

can anyone explain the working of this calculation so we can get there?


  • If you set the rate to 1000 you should get 1000 token for 1 ETH. What are you getting?
    – I.B
    Commented Jan 3, 2018 at 15:14
  • 1,000,000,000,000,000,000,000 tokens
    – Meek
    Commented Jan 3, 2018 at 16:59
  • 1
    Can you show how you initialize the values in the constructeur?
    – I.B
    Commented Jan 3, 2018 at 17:25
  • Currently using the pane available in Remix to pass the parameters into the function E.G "1515058816", "1515318016", "1000", "0x9D0E154f6C85378cE43d9b95c9Df51131E7b369A"
    – Meek
    Commented Jan 4, 2018 at 9:44
  • 1000 being the rate
    – Meek
    Commented Jan 4, 2018 at 9:44

1 Answer 1


This is likely due to your decimals value. I'm assuming you have the tokens decimals set to 18? Notice that instead of 1000 tokens, you're getting 1,000,000,000,000,000,000, where 18 of those 0s are from your decimals variable and the other 3 are the 1000. This is all expected behavior.

  • there is no decimal point after 1000 it's just straight 0's, displayed in metamask and etherscan so it seems like the wei amount multiplied is making the number extremely large tried 1000000000000000000 * 0.000000000000001 which is suppose to equal 1000 mathematically but guessing thats not possible will UINT as the number that came out was "282,236,629,591,925,000,000,000,000,000,000,000,00 ."
    – Meek
    Commented Jan 4, 2018 at 9:52
  • Decimals don't exist on the Ethereum blockchain, only whole integers exist. So decimals are represented as extra zeroes and with the "decimals" variable to show where to put the decimal for the user. To make the token show up correctly in metamask, you need to properly set the decimal variable in metamask.
    – natewelch_
    Commented Jan 4, 2018 at 12:55
  • @flygoing is correct, this is because of the decimals, his answer should be accepted
    – Julien
    Commented Jan 15, 2018 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.