web3 python的buildtransaction太慢了
我正在尝试从Web3 Python库构建交易。
swap_transaction = transaction.buildTransaction(
{
"from": Address,
"gas": 300000,
"gasPrice": w3.eth.gas_price,
"nonce": nonce,
}
)
我遇到了一个问题,即这种构建需要太多时间,例如2-3分钟。 如何使其更快?
I'm trying to build transaction from web3 python library.
swap_transaction = transaction.buildTransaction(
{
"from": Address,
"gas": 300000,
"gasPrice": w3.eth.gas_price,
"nonce": nonce,
}
)
I met a problem that this build takes too much time, like 2-3 mins.
How to make it faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了您的问题,因为我的构建时间也很慢。25秒钟左右。我不知道为什么这么慢,但是我认为该工具实际上并没有做太多。
如果您查看buildtransaction函数的结果,它只是一个简单的dict,其中包含一些添加(a'至'''字段,链条,如果您调用合同功能调用,数据字段)。
这些字段很容易自行插入。如果要添加合同功能调用的数据,可以使用EncodeAbi函数(例如:
然后将数据添加到TX参数阵列中)获得。
这样做将我的TX的建立时间从25秒的时间减少到毫秒。
I found your question as I too have a very slow build time.. 25 seconds or so. I have no idea why it is so slow, but I figured that the tool wasn't actually doing much.
If you look at the result of the buildTransaction function, it's just a simple dict with a few additions (a 'to' field, chainId, and if you are calling a contract function call, a data field).
These fields are easily inserted on your own. If you want to add data for a contract function call, you can get that by using the encodeABI function, eg:
and then add the data to your TX parameters array.
Doing it this way reduced my TX build time from something like 25 seconds to milliseconds.