---
title: "eth_estimateGas"
description: "Estimates gas needed for a transaction (Sonic)"
url: "https://blockreq.com/docs/build/api-reference/sonic/eth_estimateGas/"
---

# eth_estimateGas

**Network:** Sonic · Mainnet · Chain ID `146` (`0x92`)

**Counts as 1 request.** See [Request Counting](https://blockreq.com/docs/pricing/request-counting/index.md).

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain.

## Parameters

1. `Object` — Transaction call object (same as `eth_call`):
   | Field | Type | Required | Description |
   |-------|------|----------|-------------|
   | from | DATA | No | Sender address |
   | to | DATA | No | Recipient address |
   | gas | QUANTITY | No | Gas limit |
   | gasPrice | QUANTITY | No | Gas price |
   | value | QUANTITY | No | Value in wei |
   | data | DATA | No | Call data |

2. `QUANTITY|TAG` — (Optional) Block number, or `"latest"`.

## Returns

`QUANTITY` — The estimated amount of gas.

## Request

```json
{
  "jsonrpc": "2.0",
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
      "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "value": "0x0",
      "data": "0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"
    }
  ],
  "id": 1
}
```

## Response

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

## Code Examples

**cURL**

```bash
curl -X POST https://sonic-rpc.blockreq.com/v1/rpc/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","value":"0x0","data":"0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"}],"id":1}'
```

**TypeScript**

```typescript
const response = await fetch("https://sonic-rpc.blockreq.com/v1/rpc/public", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "jsonrpc": "2.0",
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
      "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "value": "0x0",
      "data": "0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"
    }
  ],
  "id": 1
}),
});
const data = await response.json();
console.log(data.result);
```

**Python**

```python
import requests

response = requests.post(
    "https://sonic-rpc.blockreq.com/v1/rpc/public",
    json={
  "jsonrpc": "2.0",
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
      "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "value": "0x0",
      "data": "0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"
    }
  ],
  "id": 1
}
)
print(response.json()["result"])
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := []byte(`{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","value":"0x0","data":"0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"}],"id":1}`)
	resp, err := http.Post(
		"https://sonic-rpc.blockreq.com/v1/rpc/public",
		"application/json",
		bytes.NewBuffer(payload),
	)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	var result map[string]interface{}
	json.Unmarshal(body, &result)
	fmt.Println(result["result"])
}
```

**viem**

```typescript
import { createPublicClient, http } from "viem";

const client = createPublicClient({
  transport: http("https://sonic-rpc.blockreq.com/v1/rpc/public"),
});

const result = await client.request({
  method: "eth_estimateGas",
  params: [{"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","value":"0x0","data":"0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"}],
});
console.log(result);
```

**Foundry**

```bash
cast rpc --rpc-url https://sonic-rpc.blockreq.com/v1/rpc/public eth_estimateGas {"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","value":"0x0","data":"0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"}
```

**Hardhat**

```javascript
const { ethers } = require("hardhat");

async function main() {
  const provider = new ethers.JsonRpcProvider("https://sonic-rpc.blockreq.com/v1/rpc/public");
  const result = await provider.send("eth_estimateGas", [{"from":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","to":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","value":"0x0","data":"0xa9059cbb0000000000000000000000001234567890abcdef1234567890abcdef1234567800000000000000000000000000000000000000000000000000000000000f4240"}]);
  console.log(result);
}

main();
```
