0

I am facing some issue with the token transfer , when I am using REMIX with Metamask , the transfer of the tokens from a non owner account to another account works fine . However when using MEW or MIST the transaction fails .

  function transfer(address _to, uint _value) returns (bool success){
      require( balances[msg.sender] >= _value &&
          _value > 0 );
          _value     = _value.mul(1000000000000000000);
          balances[msg.sender]  = balances[msg.sender].sub(_value);
          balances[_to]  = balances[_to].add(_value);
          Transfer(msg.sender,_to,_value);
          return true;
  }

  function transferFrom(address _from, address _to, uint _value) returns (bool success){
      require( balances[_from] >= _value && _value > 0 );
    _value     = _value.mul(1000000000000000000);
    balances[_from]  = balances[_from].sub(_value);
    balances[_to]    = balances[_to].add(_value);
    Transfer(_from,_to,_value);
    return true;
  }
8
  • Difficult to tell based on this info - a Tx hash or example Tx would be something. A guess, however: if your contract sets decimals to 18 then the multiplication by 10^18 may be duplicated by Mist & MEW. I.e. You try to transfer 1 whole token in MEW; it picks up the decimals setting and multiplies by 10^18 to get the number of base tokens; the contract multiplies again by 10^18, but you don't have 10^36 base tokens. As I say, a guess. Oct 14, 2017 at 10:26
  • But in case of metamask with remix it works fine ...
    – Naval
    Oct 14, 2017 at 10:37
  • Yes - that's my point. I don't think Metamask will take into account the decimals value of the token. What you need to do is compare the transaction data of a successful Tx with Metamask and an unsuccessful with MEW or Mist. This will reveal everything. Add the info to your question if you need a hand interpreting it. I'm happy to look at it. Oct 14, 2017 at 10:40
  • The transaction which failed is ropsten.etherscan.io/tx/…
    – Naval
    Oct 14, 2017 at 10:50
  • This transaction is trying to transfer 10^22 base tokens (0x21e19e0c9bab2400000). You then multiply by 10^18 in your contract. Unless you have have 10^40 base tokens in your account then it will fail. I expect you intended to transfer 10,000 tokens, but the UI has multiplied it by 10^18 to account for the decimals value of the contract - if so then I guessed right :-) Oct 14, 2017 at 10:57

1 Answer 1

0

The transaction which failed is ropsten.etherscan.io/tx/...

This transaction is trying to transfer 10^22 base tokens (0x21e19e0c9bab2400000). You then multiply by 10^18 in your contract. Unless you have have 10^40 base tokens in your account then it will fail.

I expect you intended to transfer 10,000 tokens, but the UI (MEW and Mist, but not in the case of Metamask) has multiplied it by 10^18 to account for the decimals value provided the contract.

You can either set decimals to 0, or remove the multiplication by 10^18 to make this more intuitive. In my token contracts I have no decimals and no multiplication! But the usual ERC20 token contract approach is to not do the multiplication. They assume all input and internal data is in terms of the base token. The decimals value is then used for front-end UIs to display and convert from display tokens to base tokens. It is a big source of confusion, and you need to know if your front-end is doing the conversion or not. Usually you can work it out based on the account balance they show you. But, yeah, it's not great.

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.