Description of the issue: I do not have sufficient funds in my wallet to transfer a token from my wallet to an external wallet. So the transaction will fail and shows us an error message. Instead of that error message I would like to show the value of estimated gas price. For that I am looking for API template. Please do suggest if you have any alternative solutions for the same.

  • What do you mean by template? Each contract is different gas costs can have large variation even among similar contracts. Look at the Etherchain table etherchain.org/tools/gasnow.
    – Ismael
    Jan 8 at 5:40
  • I need an api to give estimated gas price for that specific transaction. The code of the API may looks like below . I am asking , Since I am not sure how exactly it's look like api.etherscan.io/api ?module=gastracker &action=gasestimate &gasprice=2000000000 &apikey=YourApiKeyToken Jan 10 at 7:30
  • You don't need an API you could use web3.eth.estimateGas, see here for an example ethereum.stackexchange.com/questions/21510/….
    – Ismael
    Jan 11 at 0:12

1 Answer 1


tx.gasprice should do the trick. Although would recommend not relying on this in long run since it can be manipulated by miners. Alternative is block.baseFee which doesn't give all gas spent, but rather the baseFee spent (this can't be manipulated like the other).

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.