Day153 — get maxPriorityFeePerGas and maxFeePerGas
I did a project that involves getting the estimated gas for a EIP-1559 transaction so that it could proceed smoothly.
In the ethers.js library, it provides a method getFeeData()
to get the estimated gas, which is maxPriorityFeePerGas
and maxFeePerGas
.
but as you can see, the maxPriorityFeePerGas
is hardcoded as 1500000000 wei (1.5 gwei). That is not ideal.
To get the maxPriorityFeePerGas, a custom rpc method is called
await provider.send("eth_maxPriorityFeePerGas", [])
referencing below in alchemy-web3
const fee = await web3.eth.getMaxPriorityFeePerGas();
There is a easier way to do it. It is to use official api to get the gas estimation provided in different level.