0

I am trying to transfer a erc20 token.

   const data = contract.methods.transfer(recipient, amount).encodeABI();   
   const rawTx = {
        from: sender,
        nonce: '0x' + count.toString(16),
        gasPrice: this.web3.utils.toHex(2000000000),
        gasLimit: estimateGas,
        to: contracts.address,
        value: '0x0',
        data: data,
        chainId: '0x' + contracts.chainId
      };
      console.log(rawTx);

      const privKeyBuffer = new Buffer.from(senderPrivateKey, 'hex');
        const tx = new EthereumTx(rawTx);
        tx.sign(privKeyBuffer);
        const serializedTx = tx.serialize();
        const signedTransaction =  '0x' + serializedTx.toString('hex');
        console.log(signedTransaction);

but when I try to trace_rawTransaction, to see if the transaction is alright, I get this output:

{
    "jsonrpc": "2.0",
    "result": {
        "output": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e536166654d6174683a207375627472616374696f6e206f766572666c6f770000",
        "stateDiff": null,
        "trace": [
            {
                "action": {
                    "callType": "call",
                    "from": "0x...",
                    "gas": "0x7470",
                    "input": "0xa9059cbb0000000000000000000000004b346650ea60d22583c9e47a44b49120ae2638250000000000000000000000000000000000000000000000000de0b6b3a7640000",
                    "to": "0x...",
                    "value": "0x0"
                },
                "error": "Reverted",
                "subtraces": 0,
                "traceAddress": [],
                "type": "call"
            }
        ],
        "vmTrace": null
    },
    "id": 1
}

The output is :

SafeMath: subtraction overflow

What is happening?

  • What is data??? – goodvibration Oct 13 '19 at 5:25
  • const data = contract.methods.transfer(recipient, amount).encodeABI();, transfer is a ERC20 function in the ABI file. – Alvin Oct 14 '19 at 1:45
  • hm, do you have enough balance to transfer that amount plus gas fee? – Chan-Ho Suh Oct 14 '19 at 4:37
  • What is the implementation of transfer? (I'm trying to guide you to the point where you realize that the subtraction overflow is in that function, where you should be able to easily understand why you're getting it). – goodvibration Oct 14 '19 at 7:40
  • @Chan-HoSuh Yes I have enough balance and gas. – Alvin Oct 15 '19 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.