I'm executing transactions on mainnet with a NodeJS script:
async function send(web3, transaction, destAddr, gasPrice, privateKey) {
const options = {
data : transaction.encodeABI(),
to : destAddr,
gasPrice: gasPrice,
gas : (await web3.eth.getBlock("latest")).gasLimit
};
const signed = await web3.eth.accounts.signTransaction(options, privateKey);
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
return receipt;
}
Every transaction takes ages to complete.
I keep raising the gas-price, but no improvement.
I've finally tried to reduce the gas-limit, and instead of taking the max gas-limit per block, I just wrote "500000", which is far less than the block gas-limit, but far more than the actual gas required for each transaction.
All of the sudden, the network has started to process my transactions much faster.
It feels as if a high gas-limit "scares off" miners or something.
I've tried using await transaction.estimateGas()
but it's been giving me a "gas required exceeds allowance or always failing transaction" error every time.
I believe that this is possibly because this function underestimates the actual gas required for the transaction, so I am somewhat reluctant to use it.
Would anyone here be able to shed some light on this?
Thank you!