【问题标题】:How to use modify_transaction after send_raw_transaction in web3.py如何在 web3.py 中的 send_raw_transaction 之后使用 modify_transaction
【发布时间】:2022-11-16 19:53:55
【问题描述】:

我正在使用 Infura 节点,因此我必须使用 w3.eth.account.sign_transaction 签署交易,然后使用 w3.eth.send_raw_transaction 发送它。

我用的 gas 显然太低了,现在交易等待 8 小时。

通过查看文档,我注意到有两种方法可以帮助我 w3.eth.modify_transactionw3.eth.replace_transaction。 这个想法是使用其中之一(虽然不确定它们之间有什么区别)来修改交易气体,以便得到确认。

问题是,我在文档中看不到如何使用这两种方法之一并使用我的私钥签署修改后的交易,因为它们都对 eth_sendTransaction 进行 RPC 调用,共享 Infura 不支持节点。

【问题讨论】:

    标签: python ethereum web3py


    【解决方案1】:

    You can use local account signing middleware with Web3.py 所以你不需要使用 send_raw_transaction

    【讨论】:

      【解决方案2】:

      使用 Web3.py 5 手动增加 gas 的示例

      from web3.exceptions import TransactionNotFound
      
      tx, receipt = None, None
      try: tx = w3.eth.get_transaction (tx_hash)  # Not 100% reliable!
      except TransactionNotFound: pass
      try: receipt = w3.eth.get_transaction_receipt (tx_hash)
      except TransactionNotFound: pass
      
      if not receipt and tx:
        tx = tx.__dict__
        gas_price = tx['maxFeePerGas'] / 1000000000
        if gas_price <= 10:
          tx['maxFeePerGas'] = 12300000000
          tx['maxPriorityFeePerGas'] = 1230000000
          tx.pop ('blockHash', '')
          tx.pop ('blockNumber', '')
          tx.pop ('transactionIndex', '')
          tx.pop ('gasPrice', '')
          tx.pop ('hash', '')
          tx['data'] = tx.pop ('input')
      
          signed = w3.eth.account.sign_transaction (tx, pk)
          tid = w3.eth.send_raw_transaction (signed.rawTransaction)
          print (tid.hex())
      

      根据我的经验,maxFeePerGasmaxPriorityFeePerGas 似乎都应该增加。有一些讨论here

      【讨论】:

        猜你喜欢
        • 2018-12-01
        • 2020-10-15
        • 2019-12-18
        • 2021-07-01
        • 2021-07-28
        • 2020-03-23
        • 2018-12-01
        • 2021-03-03
        • 2022-06-25
        相关资源
        最近更新 更多