If I want to send a transaction on my frontend of my smart contract I have the possibility to set the optional field gasPrice. Should I set this value on my own, fetching it from an oracle like ETH Gas Stadion? Or does a third party provider like Metamask do this for me?



Wallets themselves use internal gas price oracles and one of those may come from Ethereum nodes themselves. But they are free to use whatever magic and choices they want to allow user to control the gas price.

Based on my experience developing on Ethereum since 2016, it is better to control the gas price yourself. Wallet gas price oracles are hit and miss. You get tons of complaints of "stuck" transactions when the tx fee was underpriced. This way, you can fix any problems very quickly if you see your gas prices start to behave weirdly. Problems in wallets get never fixed timely.

Note that many wallets also ignore whatever gas price you give to them.

You will also need to manually set gasLimit (or gas - two different name for the same variable), as the gas usage estimator of the wallets often fails and defaults to 6M gas spend, making the transaction cost appear as > $1000 in the wallet UI.

| improve this answer | |

If you don't set it explicitly, then the value enclosed in the promise returned by function web3.eth.getGasPrice is used by default.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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