跳转到内容

eth_gasPrice

返回当前每单位 Gas 的价格(wei)。

无。

QUANTITY — 当前 Gas Price(单位 wei)。

Terminal window
curl -X POST https://eth-mainnet.blockreq.com/v1/rpc/public \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}'
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x3b9aca00"
}

0x3b9aca00 = 1,000,000,000 wei = 1 Gwei

import { JsonRpcProvider, formatUnits } from "ethers";
const provider = new JsonRpcProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY");
const feeData = await provider.getFeeData();
console.log("Gas price:", formatUnits(feeData.gasPrice, "gwei"), "Gwei");
from web3 import Web3
w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY"))
gas_price = w3.eth.gas_price
print(f"Gas price: {w3.from_wei(gas_price, 'gwei')} Gwei")
MethodCost
eth_gasPrice5 RU