首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.sendSignedTransaction()不发送Tx

.sendSignedTransaction()不发送Tx
EN

Stack Overflow用户
提问于 2022-10-25 10:14:03
回答 1查看 40关注 0票数 0

一些上下文;这在Goerli上运行得很好,只需几天,但是脚本现在间歇地工作。目前,我认为这可以归结为以下几点之一:

  1. Node问题--目前正在使用呋喃,并试图在其他公共RPCS之间更改它,但没有解决任何更好的
  2. Web3问题--不确定现在是否有什么东西已经过时了,是否在钱包中出现了
  3. 当前的问题,也不确定这里的代码中是否有明显的东西会导致Txs卡住,因此永远不会返回收据

由于某种原因,这一切昨天晚上都工作得很好,因为一整天都没有工作。不知道我可能做错了什么。逻辑是,基于mempool,sendTx函数是用'targetAddress‘param调用的,其中包含复制我正在跟踪的tx所需的所有对象。

Tx.js:

代码语言:javascript
复制
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处停止,不返回收据。正如我所说的,这个有时会像预期的那样工作吗?我可以找出为什么有时工作,有时却不能工作?

谢谢大家!

EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74192460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档