问题
I am using web3js v1.0.0-beta.34 to send signed transactions to a geth node Geth/v1.8.13-unstable-2e0391ea/linux-amd64/go1.10.3 in a loop.
Problem: In the initial iterations of the loop, Node.js prints the transaction hash to console. But when the loop has been running for more than a handful of seconds, we start to get the error:
Error: Failed to check for transaction receipt: {} at Object._fireError (/Users/x/test/node_modules/web3-utils/src/index.js:56:17) at /Users/x/test/node_modules/web3-core-method/src/index.js:260:23 at <anonymous>
What can be the cause of this problem?
test.js
for (var i = nonce; i < nonce + 1000; i++) {
nounce = web3.utils.numberToHex(nonce)
receivingAddr = getRandomWalletAddress()
var rawTx = {
nonce: i,
gasPrice: gasPriceHex,
gasLimit: gasLimitHex,
to: receivingAddr,
value: txValue,
data: txData
}
var tx = new Tx(rawTx);
tx.sign(key);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', (receipt) => {
console.log(receipt.transactionHash)
})
}
回答1:
This happened because web3.js couldn't get the transaction receipt, you can see the code here: https://github.com/ethereum/web3.js/blob/1.0/packages/web3-core-method/src/index.js#L261
You can simply reproduce the error by calling eth.getTransactionReceipt and find what happened.
来源:https://stackoverflow.com/questions/51410883/web3-js-sendsignedtransaction-gives-error-failed-to-check-for-transaction-rece