# zks_estimateFee

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

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

Estimates the fee for a given call request.

Reference: https://www.alchemy.com/docs/chains/zksync/zk-sync-api-endpoints/zks-estimate-fee

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Call object | object | Yes | The transaction call object containing details about the transaction. |

## Result

**Fee estimation** (object): The estimated gas and fee details for the given call request.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "zks_estimateFee",
  "params": [
    {
      "from": "0x1111111111111111111111111111111111111111",
      "to": "0x2222222222222222222222222222222222222222",
      "data": "0xffffffff"
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "gas_limit": "0x1ea9a9",
    "max_fee_per_gas": "0x17d7840",
    "max_priority_fee_per_gas": "0x0",
    "gas_per_pubdata_limit": "0x5340"
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://zksync-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "zks_estimateFee",
  "params": [
    {
      "from": "0x1111111111111111111111111111111111111111",
      "to": "0x2222222222222222222222222222222222222222",
      "data": "0xffffffff"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'zks_estimateFee',
    params: [
      {
        from: '0x1111111111111111111111111111111111111111',
        to: '0x2222222222222222222222222222222222222222',
        data: '0xffffffff'
      }
    ]
  })
};

fetch('https://zksync-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://zksync-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "zks_estimateFee",
    "params": [
        {
            "from": "0x1111111111111111111111111111111111111111",
            "to": "0x2222222222222222222222222222222222222222",
            "data": "0xffffffff"
        }
    ]
}
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://zksync-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"zks_estimateFee\",\n  \"params\": [\n    {\n      \"from\": \"0x1111111111111111111111111111111111111111\",\n      \"to\": \"0x2222222222222222222222222222222222222222\",\n      \"data\": \"0xffffffff\"\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://zksync-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"zks_estimateFee\",\n  \"params\": [\n    {\n      \"from\": \"0x1111111111111111111111111111111111111111\",\n      \"to\": \"0x2222222222222222222222222222222222222222\",\n      \"data\": \"0xffffffff\"\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://zksync-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\": \"zks_estimateFee\",\n  \"params\": [\n    {\n      \"from\": \"0x1111111111111111111111111111111111111111\",\n      \"to\": \"0x2222222222222222222222222222222222222222\",\n      \"data\": \"0xffffffff\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: zks_estimateFee
summary: Estimates the fee for a given call request.
description: Estimates the fee for a given call request.
params:
  - name: Call object
    required: true
    description: The transaction call object containing details about the transaction.
    schema:
      type: object
      title: Call Request Object
      additionalProperties: false
      properties:
        from:
          title: From address
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
          description: The address the transaction is sent from.
        to:
          title: To address
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
          description: The address the transaction is directed to.
        gas:
          title: Gas
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          description: Gas provided for the transaction execution.
        gasPrice:
          title: Gas price
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          description: Gas price used for each paid gas.
        value:
          title: Value
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          description: Value sent with this transaction.
        data:
          title: Data
          type: string
          pattern: ^0x[0-9a-f]*$
          description: The compiled code of a contract OR the hash of the invoked method signature and encoded parameters.
        nonce:
          title: Nonce
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          description: The number of transactions sent from the address.
result:
  name: Fee estimation
  description: The estimated gas and fee details for the given call request.
  schema:
    type: object
    title: Fee Estimate
    required:
      - gas_limit
      - max_fee_per_gas
      - max_priority_fee_per_gas
      - gas_per_pubdata_limit
    properties:
      gas_limit:
        title: Gas limit
        type: string
        pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        description: The maximum amount of gas that can be used.
      max_fee_per_gas:
        title: Max fee per gas
        type: string
        pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        description: The maximum fee per unit of gas that the sender is willing to pay.
      max_priority_fee_per_gas:
        title: Max priority fee per gas
        type: string
        pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        description: The maximum priority fee per unit of gas to incentivize miners.
      gas_per_pubdata_limit:
        title: Gas per pubdata limit
        type: string
        pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        description: The gas limit per unit of public data.
examples:
  - name: zks_estimateFee example
    params:
      - name: Call object
        value:
          from: '0x1111111111111111111111111111111111111111'
          to: '0x2222222222222222222222222222222222222222'
          data: '0xffffffff'
    result:
      name: Fee estimation
      value:
        gas_limit: '0x1ea9a9'
        max_fee_per_gas: '0x17d7840'
        max_priority_fee_per_gas: '0x0'
        gas_per_pubdata_limit: '0x5340'
```
