How to get the gasPrice from the RPC?

Created by Mayank Singhal, Modified on Tue, 14 Jul at 2:18 PM by Mayank Singhal

Yes, this is possible on Polygon Mainnet using the standard JSON-RPC method eth_gasPrice.


For available RPC endpoints, see our RPC Endpoints documentation and choose one that suits your needs. We don't recommend any single RPC provider.


Using curl

curl <YOUR_MAINNET_RPC_URL> \

  -X POST \

  -H "Content-Type: application/json" \

  -d '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}'


Response is hex-encoded wei — convert to decimal (divide by 1e9 for Gwei).


Using ethers.js

const provider = new ethers.JsonRpcProvider(RPC_URL);

const gasPrice = (await provider.getFeeData()).gasPrice;


Using web3.js

const gasPrice = await web3.eth.getGasPrice();


Polygon Mainnet supports EIP-1559, so eth_gasPrice gives a legacy estimate.


For more accurate fees, also consider eth_maxPriorityFeePerGas or eth_feeHistory.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article