# linea_estimateGas

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://linea-mainnet.g.alchemy.com/v2/{apiKey}

Generates and returns the estimated amount of gas required to allow the transaction to complete and be published on Ethereum. This method does not submit the transaction to the blockchain. The priorityFeePerGas returned includes the cost of submitting the transaction to Ethereum, which can vary based on the size of the calldata.


Reference: https://www.alchemy.com/docs/chains/linea/linea-api-endpoints/linea-estimate-gas

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Call object | object | Yes | The transaction call object. |
| State override object | object | No | Optional object to override account state for simulation. |

## Result

**Gas estimation result** (object): Estimated gas limit, base fee, and priority fee.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "linea_estimateGas",
  "params": [
    {
      "from": "0x42c27251C710864Cf76f1b9918Ace3E585e6E21b",
      "value": "0x1",
      "gasPrice": "0x100000000",
      "gas": "0x21000"
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "gasLimit": "0xcf08",
    "baseFeePerGas": "0x7",
    "priorityFeePerGas": "0x43a82a4"
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://linea-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "linea_estimateGas",
  "params": [
    {
      "from": "0x42c27251C710864Cf76f1b9918Ace3E585e6E21b",
      "value": "0x1",
      "gasPrice": "0x100000000",
      "gas": "0x21000"
    },
    {
      "property1": {
        "balance": "string",
        "nonce": "string",
        "code": "string",
        "stateDiff": {
          "property1": "string"
        }
      }
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'linea_estimateGas',
    params: [
      {
        from: '0x42c27251C710864Cf76f1b9918Ace3E585e6E21b',
        value: '0x1',
        gasPrice: '0x100000000',
        gas: '0x21000'
      },
      {
        property1: {
          balance: 'string',
          nonce: 'string',
          code: 'string',
          stateDiff: {property1: 'string'}
        }
      }
    ]
  })
};

fetch('https://linea-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://linea-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "linea_estimateGas",
    "params": [{
            "from": "0x42c27251C710864Cf76f1b9918Ace3E585e6E21b",
            "value": "0x1",
            "gasPrice": "0x100000000",
            "gas": "0x21000"
        }, { "property1": {
                "balance": "string",
                "nonce": "string",
                "code": "string",
                "stateDiff": { "property1": "string" }
            } }]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://linea-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"linea_estimateGas\",\n  \"params\": [\n    {\n      \"from\": \"0x42c27251C710864Cf76f1b9918Ace3E585e6E21b\",\n      \"value\": \"0x1\",\n      \"gasPrice\": \"0x100000000\",\n      \"gas\": \"0x21000\"\n    },\n    {\n      \"property1\": {\n        \"balance\": \"string\",\n        \"nonce\": \"string\",\n        \"code\": \"string\",\n        \"stateDiff\": {\n          \"property1\": \"string\"\n        }\n      }\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://linea-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"linea_estimateGas\",\n  \"params\": [\n    {\n      \"from\": \"0x42c27251C710864Cf76f1b9918Ace3E585e6E21b\",\n      \"value\": \"0x1\",\n      \"gasPrice\": \"0x100000000\",\n      \"gas\": \"0x21000\"\n    },\n    {\n      \"property1\": {\n        \"balance\": \"string\",\n        \"nonce\": \"string\",\n        \"code\": \"string\",\n        \"stateDiff\": {\n          \"property1\": \"string\"\n        }\n      }\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://linea-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"linea_estimateGas\",\n  \"params\": [\n    {\n      \"from\": \"0x42c27251C710864Cf76f1b9918Ace3E585e6E21b\",\n      \"value\": \"0x1\",\n      \"gasPrice\": \"0x100000000\",\n      \"gas\": \"0x21000\"\n    },\n    {\n      \"property1\": {\n        \"balance\": \"string\",\n        \"nonce\": \"string\",\n        \"code\": \"string\",\n        \"stateDiff\": {\n          \"property1\": \"string\"\n        }\n      }\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: linea_estimateGas
description: |
  Generates and returns the estimated amount of gas required to allow the transaction to complete and be published on Ethereum. This method does not submit the transaction to the blockchain. The priorityFeePerGas returned includes the cost of submitting the transaction to Ethereum, which can vary based on the size of the calldata.
params:
  - name: Call object
    required: true
    description: The transaction call object.
    schema:
      type: object
      required: []
      additionalProperties: false
      properties:
        from:
          type: string
          description: 20-byte sender address.
        to:
          type: string
          description: 20-byte recipient address.
        gas:
          type: string
          description: Hexadecimal gas limit for execution.
        gasPrice:
          type: string
          description: Hexadecimal gas price per unit.
        maxPriorityFeePerGas:
          type: string
          description: Max priority fee per gas in wei.
        maxFeePerGas:
          type: string
          description: Max total fee (base + priority) per gas in wei.
        value:
          type: string
          description: Hexadecimal value of ETH to send with the transaction.
        data:
          type: string
          description: ABI-encoded data (function selector + params).
  - name: State override object
    required: false
    description: Optional object to override account state for simulation.
    schema:
      type: object
      description: Mapping of account addresses to temporary override objects.
      additionalProperties:
        type: object
        required: []
        additionalProperties: false
        properties:
          balance:
            type: string
            description: Hexadecimal temporary balance override.
          nonce:
            type: string
            description: Hexadecimal temporary nonce override.
          code:
            type: string
            description: Temporary bytecode override.
          stateDiff:
            type: object
            description: Storage slot override map.
            additionalProperties:
              type: string
result:
  name: Gas estimation result
  description: Estimated gas limit, base fee, and priority fee.
  schema:
    type: object
    required:
      - gasLimit
      - baseFeePerGas
      - priorityFeePerGas
    additionalProperties: false
    properties:
      gasLimit:
        type: string
        description: Recommended gas limit for the transaction.
      baseFeePerGas:
        type: string
        description: Estimated base fee per gas in hexadecimal format.
      priorityFeePerGas:
        type: string
        description: Estimated priority fee per gas in hexadecimal format.
examples:
  - name: Simple ETH transfer
    params:
      - name: Call object
        value:
          from: '0x42c27251C710864Cf76f1b9918Ace3E585e6E21b'
          value: '0x1'
          gasPrice: '0x100000000'
          gas: '0x21000'
    result:
      name: Gas estimation result
      value:
        gasLimit: '0xcf08'
        baseFeePerGas: '0x7'
        priorityFeePerGas: '0x43a82a4'
```
