1

Wrapping my head around totalSupply, decimals, wei, and ether is getting me very confused.

For the purposes of education, I'm trying to make an ERC20 token contract that is capped at only ONE token. My understanding is that, since Solidity doesn't deal with floating point numbers, by setting my decimals to 18, I actually have 1e18 "parts" to this "one token" of mine.

Please correct me if my understanding is wrong. But I'm going to keep going.


So I've been trying to follow this tutorial and it makes use of:

  • A token contract that inherits from MintableToken, and;
  • A crowdsale contract that inherits from TimedCrowdsale and MintedCrowdsale.

In order to change this to a capped supply token, I just made the token contract inherit from CappedToken instead, added the necessary constructor method, and initialized the cap amount on deployment.

The crowdsale contract takes a rate value, which I assume is how many tokens to return to the user for 1 wei.

There are basically 3 parameters at this point:

  • decimals = 18
  • rate = 1
  • cap = 1e18

I'm a bit confused at this point because I keep getting cryptic reverts when I try to send in 1 wei. Shouldn't 1 wei buy me 1 of my coins?

1 Answer 1

1

I just reviewed the tutorial in more detail and I've found that the parameters they used were:

  • decimals = 18
  • rate = 1000

They had no supply limit, but spending 5 Ethers got you 5000 of those coins. So this means that the rate tells you how many coins you get per Ether, not Wei as I had previously assumed.

This means that if I want my coins to be 1 Ether each, I need to set the rate = 1. My cap would still be 1e18, as I described in my original question. And now, if I send in 0.002 ETH, then I will get 0.002 of my special coin.

Your Answer

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

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