【发布时间】:2018-12-26 21:31:51
【问题描述】:
我正在使用 web3js v1.0.0-beta.34 将签名交易发送到一个 geth 节点 Geth/v1.8.13-unstable-2e0391ea/linux-amd64/go1.10.3 在一个循环中。
问题:在循环的初始迭代中,Node.js 将事务哈希打印到控制台。但是当循环运行了几秒钟以上时,我们开始收到错误:
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>
这个问题的原因是什么?
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)
})
}
【问题讨论】:
-
假设您的值是正确的(尚未发布),代码在结构上没有任何问题。在
rawTx中设置值会有所帮助(尤其是生成txData的方式)。你说你得到交易哈希......结果是什么? web3js 有一个非常烦人的问题,因为通常需要很长时间才能挖掘交易,所以即使一切正常,库也会给你超时错误。不过这似乎有所不同。 -
我有一个客户几乎可以做到这一点。它会在一个循环中触发一堆已签名的交易。我可以发布一个版本作为答案,但我不确定它是否能解决这个确切的问题。
标签: node.js ethereum web3js go-ethereum geth