【问题标题】:What's the best way to achieve this?实现这一目标的最佳方法是什么?
【发布时间】:2021-12-25 15:55:04
【问题描述】:

如何在 Web3 上实现以下功能? 我在 ethers 上完美运行,但需要将某些仅接受 web3.eth.getTransaction 的网络转换为 Web3。

我需要监听待处理的事务,然后引导到与 methodID 和令牌地址匹配的 eth.getTransaction。

我应该使用 web3.eth.subscribe 吗?

Code:

provider.on('pending', async tx => {
provider.getTransaction(tx).then(function (transaction) {
if (
(transaction != null &&
transaction['data'].includes(MethodID) &&
transaction['data'].includes(TokenID))
) {
console.log(transaction);

【问题讨论】:

    标签: ethereum web3 ethers.js


    【解决方案1】:

    您可以使用pendingTransactions 订阅事件类型(docs),然后使用getTransaction() 方法(docs)。

    web3.eth.subscribe('pendingTransactions', async (err, txHash) => {
        const tx = await web3.eth.getTransaction(txHash);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      相关资源
      最近更新 更多