首页 > 解决方案 > 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))

然后,我在 Bscscan 上检查交易状态 在此处输入图像描述

交易在 05:54:42 出现在 Bscscan 上,但 sendRawTransaction 出现在 05:54:39(相差 3 秒)。是否可以最小化这个时间差?

标签: pythonblockchainweb3web3pybscscan

解决方案


如何处理交易速度?

为了更快地调整您的交易的汽油价格(交易费用)。但是,请注意更高的 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 或更高。


推荐阅读