Web3.js: Estimating Gas Prices Similar to Metamask (Low, Medium, Priority)

gasgas-pricemetamaskweb3js

I am attempting to write a tool that allows me to Mint and NFT using Web3js. Web3js provides these two methods:

        const gas = await web3.eth.getGasPrice();
        const gasLimit = (await web3.eth.getBlock("latest")).gasLimit;

My problem is that, my gas value does not match what metamask is showing me. I am also not entirely sure what gasLimit does.

How does metamask create the low/medium/priority gas functionality, is it simply adding 1 or 2 Gwei to the gas price?

Best Answer

Turns out that as of EIP-1559 the gas price should not be specified in the transaction as it will automatically be set by the transaction. However you can specify a max fee per gas and a gas priority which is how metamask does it.