Created
January 23, 2026 16:26
-
-
Save whatl3y/320e2e05c4e07b62b48a74957e21e25e to your computer and use it in GitHub Desktop.
Quickly get gasPrice for an EVM blockchain with just an RPC_URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| const RPC_URL = process.env.RPC_URL || 'https://eth.llamarpc.com'; | |
| async function getGasPrice() { | |
| try { | |
| const response = await fetch(RPC_URL, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ | |
| jsonrpc: '2.0', | |
| method: 'eth_gasPrice', | |
| params: [], | |
| id: 1, | |
| }), | |
| }); | |
| const data = await response.json(); | |
| if (data.error) { | |
| console.error('RPC Error:', data.error.message); | |
| process.exit(1); | |
| } | |
| const gasPriceWei = BigInt(data.result); | |
| const gasPriceGwei = Number(gasPriceWei) / 1e9; | |
| console.log(`RPC: ${RPC_URL}`); | |
| console.log(`Gas Price: ${gasPriceGwei.toFixed(4)} gwei`); | |
| } catch (error) { | |
| console.error('Error fetching gas price:', error.message); | |
| process.exit(1); | |
| } | |
| } | |
| getGasPrice(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment