I am new to ethereum block-chain. I create a ERC20 base smart contract. I set decimals values 18. When I call transfer function and pass the address and value parameters. So it's convert no.of token value into decimals. I want to it integer number.

I follow answer:- Correct way to transfer ERC-20 tokens and keeping decimals in count?

But one thing I can not understand how to intelize temporary variable and pass it on transfer function. I can do this way:-

Solidity code:-

contract StandardToken is ERC20, BasicToken {
   using SafeMath for uint256;
   // Name
   string public name = "Autobay";
   // Symbol
   string public symbol = 'ABX';
   string public standard = 'ABX 0.1';
   //token price
    uint256 public tokenPrice = 100000; //in wei
    uint256 public  amount;
    uint256 public constant decimals = 18;
    uint256 public totalSupply;

   constructor(uint256 _intialSupply) {
      balances[msg.sender] = _intialSupply;
      totalSupply = _intialSupply;

   event Transfer(address indexed _form,address indexed _to,uint256 amount);
   event Approval(address indexed _owner,address indexed _spender,uint256 _value);
   mapping (address => mapping (address => uint256)) internal allowed;

   function transfer(address _to, uint256 _value) public returns (bool) {
      amount = _value * 10**decimals;
      require(_to != address(0));
      require(amount <= balances[msg.sender]);

      // SafeMath.sub will throw if there is not enough balance.
      balances[msg.sender] = balances[msg.sender].sub(amount);
      balances[_to] = balances[_to].add(amount);

      emit  Transfer(msg.sender, _to, amount);
      return true;

When I call transfer function nothing change. So where I do mistake. Please anyone resolve my query.

It might be a silly question but here i want to understand this concept more deeply.

Please help to clear my above query.


1 Answer 1


The token is considered f.i. as having N decimals, but the internal flow of the erc20 is not affected: any token transferred is 1 followed by N zeroes in integer representation.

So if you have let’s say 3 decimals, when you transfer ‘one’ token to someone, you shall call the transfer using ‘1000’ in the amount field.

Nobody treat the decimals differently. You can read the ‘decimals’ field and format properly your amount at the User Interface level, i.e. you read from the blockchain ‘1000’ and decimals ‘3’ and print ‘1.000’ on the screen. Or you read ‘1’ from the user input and call transfer using 1 * 10**decimals as value, ‘1000’ in this example.

So if you want to use integer value without problems, simply set to zero ‘decimals’, I.e.

decimals = 0;

and that is all.

  • Hi Rick I understand your answer. But I want to pass integer value I don't pass integer value with decimals . How can I do it?? Commented Sep 26, 2018 at 12:40
  • Simply set decimals to zero.
    – Rick Park
    Commented Sep 26, 2018 at 12:43

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.