How to get the current gas price on Ethereum using Ethers JS and JavaScript

In this tutorial, we are going to learn how to get an estimation of the current gas price on Ethereum using Ethers JS and JavaScript.

In this tutorial, we are going to learn how to get an estimation of the current gas price on Ethereum using Ethers JS and JavaScript.

To calculate the gas fees to pay to execute a transaction, you need to multiply the amount of gas the transaction will use by the gas price.

To get the gas price on the blockchain your Ethers provider is in, you can call the getGasPrice function:

const ethers = require("ethers")

const provider = new ethers.providers.Web3Provider(YOUR_PROVIDER_HERE)

// Get the current gas price
const gasPrice = await provider.getGasPrice();

It's as simple as that!

If you want to learn how to estimate the amount of gas a transaction consume to be able to compute the gas fees that a transaction will cost, check out this tutorial on how to calculate the gas fees a transaction costs:

How to estimate the gas fees for a transaction using Ethers JS
In this tutorial, we are going to learn how to estimate the gas fees that a transaction will cost using Ethers JS and JavaScript.

And that's it 🎉

Thank you for reading this article