一些上下文;这在Goerli上运行得很好,只需几天,但是脚本现在间歇地工作。目前,我认为这可以归结为以下几点之一:
。
由于某种原因,这一切昨天晚上都工作得很好,因为一整天都没有工作。不知道我可能做错了什么。逻辑是,基于mempool,sendTx函数是用'targetAddress‘param调用的,其中包含复制我正在跟踪的tx所需的所有对象。
Tx.js:
const Web3 = require('web3');
const Tx = require('ethereumjs-tx');
process.removeAllListeners('warning');
require('dotenv').config();
const INFURA_URL_TESTNET = process.env.INFURA_URL_TESTNET;
const web3 = new Web3(INFURA_URL_TESTNET);
const BN = web3.utils.BN;
// Tx details:
const sendTx = async (targetAddress) => {
const address = targetAddress.address;
const ethAmmount = targetAddress.value;
const data = targetAddress.input;
const gasLimit = targetAddress.gas;
//const gasPrice = targetAddress.gasPrice - web3.utils.toWei('1', 'gwei');
const maxFeePerGas = targetAddress.maxFeePerGas //- 1000000;
const maxPriorityFeePerGas = targetAddress.maxPriorityFeePerGas //- 1000000;
const privKey = targetAddress.privKey;
const from = targetAddress.from;
const _txCount = await web3.eth.getTransactionCount(from);
const createTransaction = await web3.eth.accounts.signTransaction(
{ to: address,
from: from,
data: data,
gas: gasLimit,
value: ethAmmount,
nonce: _txCount,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: maxPriorityFeePerGas,
},
privKey,
);
// Send Tx and Wait for Receipt
const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction);
//const transaction = await web3.eth.getTransaction(createReceipt.transactionHash);
console.log(`Tx successful with hash: ${createReceipt.transactionHash}`);
};
module.exports = {sendTx};代码在等待.sendSignedTx处停止,不返回收据。正如我所说的,这个有时会像预期的那样工作吗?我可以找出为什么有时工作,有时却不能工作?
谢谢大家!
发布于 2022-10-26 10:40:59
由于您使用的是web3js,所以在调用sendSignedTransaction并记录所有有效负载时,您必须处理事件承诺链。这会告诉你它没有被广播的原因。可能是网络错误,气体问题,可能是现在的.e.t.c。
请参阅https://web3js.readthedocs.io/en/v1.2.11/callbacks-promises-events.html#callbacks-promises-events
https://stackoverflow.com/questions/74192460
复制相似问题