2

I am trying to transfer ERC20 tokens on private ethereum network(POA)

Transaction flow:

  1. raw tx object creation on backend.
   {
        "gasLimit": 37000,
        "gasPrice": 4000000000,
        "to": <contract address>,
        "value": 0,
        "chainId": 15,
        "data": "0xa9059cbb000000000000000000000000ff70ccdc55a319428fd88809ce848a61087ab2ac0000000000000000000000000000000000000000000000003782dace9d900000"
    }
  1. sign tx on front end.
 { messageHash:
   '0x4bbc38ad53cf154ca1445365c9007dfeca0c0cce251945feb2a8ff3bd6de8795',
  v: '0x42',
  r:
   '0xa664add8c614f05d52104a29b16312744cb8849bc5af5cb78a9ba7daf19e8a12',
  s:
   '0x38c055e9a7c1e5b0321f5d82d832d91da3a2207025756b84c44b8ca31cbbb4f2',
  rawTransaction:
   '0xf8a80884ee6b280082908894324e19e928239d0c7f8b93247d559b54a4e0d03080b844a9059cbb0000000000000000000000008d75f6db12c444e290db995f2650a68159364e2500000000000000000000000000000000000000000000000270801d946c94000042a0a664add8c614f05d52104a29b16312744cb8849bc5af5cb78a9ba7daf19e8a12a038c055e9a7c1e5b0321f5d82d832d91da3a2207025756b84c44b8ca31cbbb4f2' }
  1. submit tx from backend data.
 web3.eth.sendSignedTransaction(signedData)
        .on('receipt',function(receipt:any){
            if(receipt.status == false)
                throw new Error('transaction failed');
            sendSuccessResponse(res, {
                txId : receipt.transactionHash
            });
        })
        .catch(function(error:any){
            next(error);
        })

But when I try to sign transaction on android(using web3j) and submit from backend(web3.js). It fails sometimes(for random receiving addresses such as : 0xFF70ccDC55a319428FD88809cE848a61087Ab2aC) with error: Transaction has been reverted by the EVM

    public String sign(RawTransaction rawTransaction, Credentials credentials) {
        byte[] signedMessage;
        signedMessage = TransactionEncoder.signMessage(rawTransaction, bigIntToByteArray(15), credentials);
        return Numeric.toHexString(signedMessage);
    }

version:

Web3.js - 1.2.4

Web3j - org.web3j:core:4.2.0-android

Geth - Geth/v1.9.6-stable-bd059680/linux-amd64/go1.11.5

Network consensus : POA

No. of nodes : 2

1 Answer 1

1

Transaction was failing because of fixed gasLimit : 37000.

Gas depends on what the function is doing.

For example, it is more expensive to set a zero-value storage value to non-zero, than it is to set a non-zero storage value to another non-zero storage value.

In my case it was because of SSTORE opcode as it takes 20000 when storage value is set to non-zero from zero and 5000 when the storage value's remains unchanged or is set to zero.

So changed 37000 to 52000 and it worked as expected.

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.