python - Bscscan 上 web3.eth.sendRawTransaction 和事务验证时间之间的时间
问题描述
我正在使用以下代码进行 web3py 合同交易:
txn = contract.functions.bid(
tokenId,
price
).buildTransaction({
'chainId': 56,
'gas': gasLimit,
'gasPrice': web3.toWei('5', 'gwei'),
'nonce': nonce
})
signed_txn = web3.eth.account.sign_transaction(txn, private_key=privateKey)
web3.eth.sendRawTransaction(web3.toHex(signed_txn.rawTransaction))
交易在 05:54:42 出现在 Bscscan 上,但 sendRawTransaction 出现在 05:54:39(相差 3 秒)。是否可以最小化这个时间差?
解决方案
如何处理交易速度?
为了更快地调整您的交易的汽油价格(交易费用)。但是,请注意更高的 GWEI = 更高的速度 = 更高的速率。
如果您没有定义 gasPrice 交易对象,它将默认为web3.eth.getGasPrice(),通常为 5 gwei。[阅读更多]
使用 5 GWEI 获得标准交易速度
.buildTransaction({
'chainId': 56,
'gas': gasLimit,
'nonce': nonce
})
使用 6 GWEI 获得快速交易速度
.buildTransaction({
'chainId': 56,
'gasPrice': web3.toWei('6', 'gwei'),
'gas': gasLimit,
'nonce': nonce
})
使用 7 GWEI 获得极快的交易速度
.buildTransaction({
'chainId': 56,
'gasPrice': web3.toWei('7', 'gwei'),
'gas': gasLimit,
'nonce': nonce
})
使用 15 GWEI 或更多以获得即时交易速度
.buildTransaction({
'chainId': 56,
'gasPrice': web3.toWei('7', 'gwei'),
'gas': gasLimit,
'nonce': nonce
})
通常 7 GWEI 对于大多数情况来说已经绰绰有余,这可能是速度和 gas 费用成本之间的最佳成本效益。
但是,如果您确实需要保证即时交易,我建议 gasPrice 为 15 GWEI 或更高。
推荐阅读
- django - Nginx,django,docker,拒绝通过本地主机连接
- sql-server - 按最大日期分组并从每个分组记录中返回文本
- r - 如何从长字符串中提取 2 个日期并将它们放在两个不同的列中?
- visual-studio-code - vscode用python扩展重命名符号,避免重复符号和冲突
- power-automate - 如何使用 Power Automate 从 MailChimps RESTful API 中提取成员信息
- git - git refspec 中的 + 是什么?
- voice-recognition - Nao Webots 模拟器的语音命令
- javascript - 检索订阅条带 node.js 的状态
- python - 使用函数中的while循环查找给定列表中第一次出现的负数
- spring-cloud-stream - Spring cloud stream rabbit binder:向DLQ发送批处理消息时出错