Chain used: Poylgon/mainnet or mumbai

I am trying to get gas fees for a contract call. I should be able to let user chose if : Medium or High

Same as metamask does it:

enter image description here

but this should be done on user side.

I tried the following code :

var gp = await signer.getGasPrice();
extra =Math.floor( gp / 2);
gas_price =  firstTwoDigits ( Number(gp) +  Number(extra));

I use it then like this:

var gasar = { gasLimit: 20000000, maxFeePerGas: gas_price, maxPriorityFeePerGas: gas_price}
// contract.callrow(arg1, gasar)

This is how i get a High priority gas fees. Looks like is not accurate at all.

How to get a better gas fees suggestion ?

1 Answer 1


Your web3js/ethers javascript frontend code is not in charge of the user gas selection. Your code enable sending the transaction to interact with your contract, but the user is free to select how much is willing to pay to get the transaction mined (the more expensive gas price, the sooner the transaction is mined).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.