eth_gasPrice
Returns the current gas price on zkSync Era in wei.
Why zkSync? Build on Matter Labs' flagship zkEVM powering the Elastic Network of interoperable hyperchains with ZK Stack modular framework, hyperchain interoperability, native account abstraction, and $1.9B in tokenized real-world assets.
Use Cases#
The eth_gasPrice method is essential for:
- Transaction pricing - Set appropriate gas prices
- Cost estimation - Calculate transaction costs before sending
- Gas monitoring - Track network congestion
- DeFi operations - Optimize costs for RWA tokenization ($1.9B, 25% market share), hyperchain deployment via ZK Stack, and cross-chain DeFi
Parameters#
This method accepts no parameters.
Request#
{
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": [],
"id": 1
}
Returns#
| Type | Description |
|---|---|
QUANTITY | Current gas price in wei (hexadecimal) |
Response#
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x3b9aca00"
}
Note: 0x3b9aca00 = 1 Gwei (1,000,000,000 wei)
Code Examples#
- cURL
- JavaScript
- Python
- Go
curl -X POST https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": [],
"id": 1
}'
import { JsonRpcProvider, formatUnits } from 'ethers';
const provider = new JsonRpcProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY');
const feeData = await provider.getFeeData();
const gasPrice = feeData.gasPrice;
console.log('Gas Price:', formatUnits(gasPrice, 'gwei'), 'Gwei');
// Calculate transaction cost
async function estimateTransactionCost(gasLimit) {
const feeData = await provider.getFeeData();
const cost = feeData.gasPrice * BigInt(gasLimit);
return formatUnits(cost, 'ether');
}
const cost = await estimateTransactionCost(21000);
console.log('Transfer cost:', cost, 'ETH');
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY'))
gas_price = w3.eth.gas_price
print(f'Gas Price: {w3.from_wei(gas_price, "gwei")} Gwei')
# Calculate transaction cost
def estimate_transaction_cost(gas_limit):
gas_price = w3.eth.gas_price
cost = gas_price * gas_limit
return w3.from_wei(cost, 'ether')
cost = estimate_transaction_cost(21000)
print(f'Transfer cost: {cost} ETH')
package main
import (
"context"
"fmt"
"log"
"math/big"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY")
if err != nil {
log.Fatal(err)
}
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
log.Fatal(err)
}
// Convert to Gwei
gwei := new(big.Float).Quo(
new(big.Float).SetInt(gasPrice),
big.NewFloat(1e9),
)
fmt.Printf("Gas Price: %f Gwei\n", gwei)
}
Error Handling#
| Error Code | Message | Description |
|---|---|---|
| -32603 | Internal error | Node error |
Related Methods#
eth_maxPriorityFeePerGas- Get priority fee (EIP-1559)eth_feeHistory- Get historical fee dataeth_estimateGas- Estimate gas needed