eth_gasPrice
返回当前每单位 Gas 的价格(wei)。
无。
QUANTITY — 当前 Gas Price(单位 wei)。
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
JavaScript (ethers.js v6)
Section titled “JavaScript (ethers.js v6)”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");Python (web3.py)
Section titled “Python (web3.py)”from web3 import Web3w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY"))gas_price = w3.eth.gas_priceprint(f"Gas price: {w3.from_wei(gas_price, 'gwei')} Gwei")| Method | Cost |
|---|---|
| eth_gasPrice | 5 RU |