Web3.js: sendSignedTransaction function is not returning a receipt (after Istanbul)

Created on 7 Oct 2019  路  6Comments  路  Source: ChainSafe/web3.js

Description

My code, which has been working fine on Ropsten Test Network is not working after the Istanbul hardfork.

Expected behavior

Calling await web3.eth.sendSignedTransaction(signedTx.rawTransaction) to return a receipt.

Actual behavior

Calling await web3.eth.sendSignedTransaction(signedTx.rawTransaction) does send out the transaction, but does not return the receipt nor resolve the promise.

Steps to reproduce the behavior

Try sending a signed transaction on Ropsten Test Network, and I think you'll be able to reproduce the issue.

Versions

  • web3.js: 1.2.1
  • nodejs: 10.15.3
  • ethereum node: Ropsten (Infura)
1.x 2.x clarification needed

Most helpful comment

@umurb-hydrogen Have not been able to reproduce this. Could you look at the example below and identify any differences between what you've been doing and a tx which executed successfully?

NB: Signing with [email protected]

const Transaction = require('ethereumjs-tx').Transaction;
const account1 = "0xAcb3e9205229D212Db914a92C77856b228B0a4E4";
const account2 = "0x458B8Adf2248709cf739149fE4BAb0B20101c4A1";

const txCount = await web3.eth.getTransactionCount(account1)

// Transaction
 const txObject = {
    nonce:    web3.utils.toHex(txCount),
    to:       account2,
    value:    web3.utils.toHex(web3.utils.toWei('0.1', 'ether')),
    gasLimit: web3.utils.toHex(21000),
    gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
 }

// Sign the transaction
const tx = new Transaction(txObject, { chain: 'ropsten', hardfork: 'istanbul' })
const pk = Buffer.from(PRIVATE_KEY_ACCOUNT_1, 'hex')
tx.sign(pk)

const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex')

 // Broadcast the transaction
const receipt = await web3.eth.sendSignedTransaction(raw)

Receipt

{
 "blockHash": "0xdbb365914fd57cfc08657eed1a843a619d51651b233d3b45648ca5658e54f14f",
 "blockNumber": 6527760,
 "contractAddress": null,
 "cumulativeGasUsed": 7643463,
 "from": "0xacb3e9205229d212db914a92c77856b228b0a4e4",
 "gasUsed": 21000,
 "logs": [],
 "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
 "status": true,
 "to": "0x458b8adf2248709cf739149fe4bab0b20101c4a1",
 "transactionHash": "0xb909b8f4074f45f067125348eb1cf71a197149dc03a37446dacd4a925963ff47",
 "transactionIndex": 70
}

Ropsten Etherscan

link to tx

[EDIT - Apologies, looked more carefully at your initial report - you're using accounts.sign? Will investigate this but suspect it will require a fix currently pending as part of #3070. Signing with ethereumjs-tx as above is a work-around.)

All 6 comments

Same identical problem, i have already opened a issue on Infura Github page:
https://github.com/INFURA/infura/issues/190
Before Istanbul on ropsten all ok, now sendSignedTransaction never solves promise. Try to change different web3 versions and situation does not change.
I am using Infura, i don't know if the problem show up also running a local full node.

@umurb-hydrogen Have not been able to reproduce this. Could you look at the example below and identify any differences between what you've been doing and a tx which executed successfully?

NB: Signing with [email protected]

const Transaction = require('ethereumjs-tx').Transaction;
const account1 = "0xAcb3e9205229D212Db914a92C77856b228B0a4E4";
const account2 = "0x458B8Adf2248709cf739149fE4BAb0B20101c4A1";

const txCount = await web3.eth.getTransactionCount(account1)

// Transaction
 const txObject = {
    nonce:    web3.utils.toHex(txCount),
    to:       account2,
    value:    web3.utils.toHex(web3.utils.toWei('0.1', 'ether')),
    gasLimit: web3.utils.toHex(21000),
    gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
 }

// Sign the transaction
const tx = new Transaction(txObject, { chain: 'ropsten', hardfork: 'istanbul' })
const pk = Buffer.from(PRIVATE_KEY_ACCOUNT_1, 'hex')
tx.sign(pk)

const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex')

 // Broadcast the transaction
const receipt = await web3.eth.sendSignedTransaction(raw)

Receipt

{
 "blockHash": "0xdbb365914fd57cfc08657eed1a843a619d51651b233d3b45648ca5658e54f14f",
 "blockNumber": 6527760,
 "contractAddress": null,
 "cumulativeGasUsed": 7643463,
 "from": "0xacb3e9205229d212db914a92c77856b228b0a4e4",
 "gasUsed": 21000,
 "logs": [],
 "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
 "status": true,
 "to": "0x458b8adf2248709cf739149fe4bab0b20101c4a1",
 "transactionHash": "0xb909b8f4074f45f067125348eb1cf71a197149dc03a37446dacd4a925963ff47",
 "transactionIndex": 70
}

Ropsten Etherscan

link to tx

[EDIT - Apologies, looked more carefully at your initial report - you're using accounts.sign? Will investigate this but suspect it will require a fix currently pending as part of #3070. Signing with ethereumjs-tx as above is a work-around.)

I have solved my problem substituting
var transaction = new Tx(txData, {chain:'ropsten'})
with
var transaction = new Tx(txData, {chain:'ropsten', hardfork: 'istanbul'}).

Thanks

Thanks for sharing the solution! Adding the hardfork information did solve the issue.

Another thing to note is that my original code (without the hardfork information) is also working at the moment. I am not sure what changed, but all is good.

I think we can close this issue.

@umurb-hydrogen

Another thing to note is that my original code (without the hardfork information) is also working at the moment. I am not sure what changed, but all is good.

Ah interesting! Perhaps the network was having some problems...

This is also being tracked in #3070 (under "transaction signing"). Closing.

Looks like it has been resolved now.

One additional thing to notice: if you are using web3 sendSignedTransaction function with infura nodes, promise is actually never resolved if nonce is too high.

Was this page helpful?
0 / 5 - 0 ratings