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?
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.