Skip to content

Instantly share code, notes, and snippets.

View DavidsDvm's full-sized avatar
🛸
Learning cool things

DavidsDvm DavidsDvm

🛸
Learning cool things
View GitHub Profile
@DavidsDvm
DavidsDvm / index.js
Created October 7, 2025 16:22
Polygon Gas Checker
import { JsonRpcProvider, formatUnits } from "ethers";
const POLYGON_RPC_URL = process.env.POLYGON_RPC_URL || "https://polygon-rpc.com";
async function getPolygonGasPriceGwei() {
const provider = new JsonRpcProvider(POLYGON_RPC_URL);
const feeData = await provider.getFeeData();
const wei = feeData.gasPrice ?? feeData.maxFeePerGas ?? feeData.lastBaseFeePerGas;
if (wei == null) {
throw new Error("No gas price available from provider");