首页 > 解决方案 > 如何找到正确的“gas”值以便在 Ropsten 测试网上发送交易?

问题描述

我是 Web3/以太坊世界的新手,我正在尝试构建一个可以通过 Infuria 将块简单地写入 Ropsten 测试网上的应用程序。不幸的是,以下代码似乎不起作用

from web3 import Web3

    def sendTransaction(message):
     w3 = Web3(
         Web3.HTTPProvider(
             "https://ropsten.infura.io/v3/my_project_id"
         )
     )
     address = "https://ropsten.infura.io/v3/my_project_id"
     privateKey =       "my_private_key"
     nonce = w3.eth.getTransactionCount(address)
     gasPrice = w3.eth.gas_price
     value = w3.toWei(1, "ether")
     signedTx = w3.eth.account.sign_transaction(
      dict(
       nonce=nonce,
       gasPrice=gasPrice,
       gas=1000000000,
       to="0x0000000000000000000000000000000000000000",
       value=value,
       data=message.encode("UTF-8"),
      ),
     privateKey,
    )
   tx = w3.eth.sendRawTransaction(signedTx.rawTransaction)
   txId = w3.toHex(tx)
   return txId

特别是现场气体似乎会产生问题。如果我添加太多零,我会收到错误消息'exceeds block gas limit',而如果零少,错误消息会变成'insufficient fund for gas * price + value'

标签: python-3.xdjangoethereumweb3python-venv

解决方案


推荐阅读