1

I'm pretty much new on this. But I really want to learn.

I just created a contract for mintable token on Kovan test-net. But, I'm getting confused when I try to buy the token, it's always shown x000.000.000.000.000.000 instead just 100 or 1000. My Token's decimal is 2 and the price is 150 for 1 ETH.

Here's the Token code :

contract Test is MintableToken {

  string public constant name = "TestToken";
  string public constant symbol = "TET";
  uint8 public constant decimals = 2;

}

And here's the 2_deploy_contract.js code

var TestTokenPresaleTest = artifacts.require("./TestTokenPresaleTest.sol");

module.exports = function(deployer, network, accounts) {
  return liveDeploy(deployer, accounts);
};

function latestTime(){
  return web3.eth.getBlock('latest').timestamp;
}

const duration = {
  seconds: function(val) { return val},
  minutes: function(val) { return val * this.seconds(60) },
  hours: function(val) {return val * this.minutes(60) },
  days: function(val) {return val * this.hours(24) },
  weeks: function(val) {return val * this.days(7) },
  years: function(val) {return val * this.days(365) }
};

async function liveDeploy(deployer, accounts){
  const BigNumber = web3.BigNumber;
  const RATE = new web3.BigNumber(100);
  const startTime = latestTime() + duration.minutes(10);
  const endTime =   startTime + duration.hours(12);
  console.log([startTime, endTime, RATE, accounts[0]]);
  // uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet)
  return deployer.deploy(TestTokenPresaleTest, startTime, endTime, RATE, accounts[0]).then( async () => {
    const instance = await TestTokenPresaleTest.deployed();
    const token = await instance.token.call();
    console.log('Token Address', token);
  })
}

I'm using OpenZepellin and Truffle for doing this.

Can anyone help?

Best Regards

4
  • can you give smart contract code for your token? Commented Oct 24, 2017 at 3:10
  • I haven't seen any codes related to transferring token to the purchaser. how are you transferring the tokens to them and where are you assigning 1 ETH is equal to 150 Tokens. Commented Oct 24, 2017 at 4:25
  • Well, basically this contract will have self address that you can send on the ETH to buy the Token. And when that's happen, the Token will be automatically transfered to the buyer, and will be recorded it the Token internal transactions. On the RATE, I assigned it as 100 as my last edit to the file.
    – sichokie
    Commented Oct 24, 2017 at 9:13
  • I think in that part of code your missing something. Commented Oct 25, 2017 at 3:26

1 Answer 1

1

I think what you're experiencing is the difference between an Ether and a Wei.

Internally, Solidity doesn't support floating-point or even fixed-point decimal variables - only integers. Consequently, everything is stored using integer values. "Ether" the currency unit is divisible to 18 decimal places. The smallest possible (indivisible) unit is called a wei.

"1 ETH" is 1 x 10 ^ 18 Wei, much like one "dollar" is 1 x 10 ^ 2 "cents".

Conversion from a human-friendly presentation such as 1.23 Ether is a user-interface concern. Internally, that is 1.23 * 10 ^ 18 wei. You get 12300000.... many zeroes.

Similarly, the internal storage of your token contract will adjust for the decimal places defined (2). So "1 token" will be stored as "100" of the smallest possible unit. The token contract includes that decimals parameter to signal user interfaces about correct way to display a friendly, expected, number.

If you are looking at the data without the aid of a user interface that converts to natural units, then you will see large numbers.

Hope it helps.

1
  • Ah, I see the point. So I have to declare the Token rate on the Token code file, right?
    – sichokie
    Commented Oct 24, 2017 at 9:16

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.