# eth_gasPrice - Gnosis RPC Method

Returns the current gas price on Gnosis in wei.

> **Why Gnosis?** Build on the prediction market pioneer with $260M+ TVL and xDAI stablecoin-based gas fees with stablecoin gas fees for predictable costs, Shutter MEV protection, 150K+ Safe wallets, and Circles decentralized UBI protocol.

## When to Use This Method

The `eth_gasPrice` method serves these key scenarios for prediction market builders, DAO tooling developers, and teams building MEV-protected applications:

- **Set gas price for legacy transactions** - Use the returned wei value as the `gasPrice` field in legacy (pre-EIP-1559) transactions on Gnosis
- **Monitor network congestion** - Track gas price fluctuations to determine the best time to submit transactions for lower fees
- **Estimate transaction costs** - Multiply gas price by estimated gas units to calculate the total cost before sending any transaction
- **Build gas price oracles** - Feed real-time gas price data into fee estimation UIs, automated trading bots, and wallet applications

## Common Use Cases

### 1. Calculate Total Transaction Cost

Multiply the current gas price by the estimated gas for a transaction to determine the total cost in the native currency of Gnosis. This lets users see the expected fee before confirming any transaction.

```javascript
import { JsonRpcProvider, formatUnits } from 'ethers';

const provider = new JsonRpcProvider('https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY');

async function calculateTransactionCost(gasLimit) {
  const gasPrice = await provider.send('eth_gasPrice', []);
  const costWei = BigInt(gasPrice) * BigInt(gasLimit);
  const costEth = formatUnits(costWei, 'ether');
  console.log(`Gas price: ${formatUnits(gasPrice, 'gwei')} Gwei`);
  console.log(`Estimated cost: ${costEth} ETH`);
  return costEth;
}

await calculateTransactionCost(21000);
```

### 2. Build Dynamic Gas Price Strategy

Adjust gas prices dynamically based on current network conditions. During peak congestion on Gnosis, multiply the base gas price by 1.2-1.5x for faster inclusion; during quiet periods, use the raw gas price for the most economical confirmation.

```javascript
import { JsonRpcProvider, formatUnits } from 'ethers';

const provider = new JsonRpcProvider('https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY');

async function getDynamicGasPrice(strategy = 'medium') {
  const baseGasPrice = BigInt(await provider.send('eth_gasPrice', []));
  const multipliers = { low: 1.0, medium: 1.2, high: 1.5 };

  const adjustedPrice = baseGasPrice * BigInt(Math.floor(multipliers[strategy] * 100)) / 100n;

  console.log(`Base gas price: ${formatUnits(baseGasPrice, 'gwei')} Gwei`);
  console.log(`Strategy (${strategy}): ${formatUnits(adjustedPrice, 'gwei')} Gwei`);
  return adjustedPrice;
}

await getDynamicGasPrice('medium');
```

### 3. Compare Gas Prices Across Chains

If your application supports multiple chains, compare gas prices to route transactions to the most cost-effective network. This is particularly useful for cross-chain bridges and multi-chain DeFi aggregators.

```javascript
const chains = {
  ethereum: 'https://eth.dwellir.com',
  polygon: 'https://polygon.dwellir.com',
  arbitrum: 'https://arb.dwellir.com'
};

async function compareGasPrices() {
  const results = {};
  for (const [name, rpcUrl] of Object.entries(chains)) {
    const provider = new JsonRpcProvider(rpcUrl);
    const gasPrice = await provider.send('eth_gasPrice', []);
    results[name] = {
      wei: BigInt(gasPrice).toString(),
      gwei: Number(BigInt(gasPrice)) / 1e9
    };
  }

  const sorted = Object.entries(results).sort((a, b) => a[1].gwei - b[1].gwei);
  console.log('Cheapest chain:', sorted[0][0], '-', sorted[0][1].gwei, 'Gwei');
  return results;
}

compareGasPrices();
```

## Best Practices

- Legacy gas price is a single number: for EIP-1559 transactions, prefer using `eth_feeHistory` combined with `eth_maxPriorityFeePerGas` instead
- The return value is in wei: divide by `1e9` to convert to gwei, which is the standard unit for gas price display
- Consider current network conditions on Gnosis: multiply by 1.2-1.5x for faster block inclusion during congestion
- Most modern chains use EIP-1559 exclusively: check if Gnosis supports dynamic fee transactions before relying on legacy gas price

## Request Parameters

This method accepts no parameters.

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "eth_gasPrice",
  "params": [],
  "id": 1
}
```

## Response Fields

- `result` (`QUANTITY, required`): Current gas price in wei (hexadecimal)

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x3b9aca00"
}
```

## Code Examples

cURL
JavaScript
Python
Go

```bash
curl -X POST https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_gasPrice",
    "params": [],
    "id": 1
  }'
```

```javascript
import { JsonRpcProvider, formatUnits } from 'ethers';

const provider = new JsonRpcProvider('https://api-gnosis-mainnet.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');
```

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-gnosis-mainnet.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')
```

```go
package main

import (
    "context"
    "fmt"
    "log"
    "math/big"

    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://api-gnosis-mainnet.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)
}
```

## Related Methods

- [`eth_maxPriorityFeePerGas`](https://www.dwellir.com/docs/gnosis/eth_maxPriorityFeePerGas) - Get priority fee (EIP-1559)
- [`eth_feeHistory`](https://www.dwellir.com/docs/gnosis/eth_feeHistory) - Get historical fee data
- [`eth_estimateGas`](https://www.dwellir.com/docs/gnosis/eth_estimateGas) - Estimate gas needed
