Day153 — get maxPriorityFeePerGas and
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
ethers.js/index.ts at 608864fc3f00390e1260048a157af00378a98e41 · ethers-io/ethers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below…
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.