python-3.x - 如何找到正确的“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'。
解决方案
推荐阅读
- pdf - 有存储大量小型 PDF 文件的好方法吗?
- php - 在 WordPress 中使用 PHP 进行可恢复文件下载/通过 WordPress 后端下载文件
- bash - 从 CLI 脚本中批量删除 IAM 角色
- visual-studio - IIS Web 部署失败并出现“未知规则:AppOffline”
- python - 根据循环内另一列的值将列的值更改为nan
- ansible - ansible-playbook:: 如何在配置以外的其他主机上播放
- firebase - 从 Firestore 获取数据
- python - Python用子目录名称重命名子目录中的文件
- python - com_error 的 pywintypes 和 pythoncom 之间的区别
- oracle - 剧院数据库的 SQL Developer 触发器