# zkevm_estimateFee

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

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

Returns the estimated transaction fee for executing the provided transaction
on Polygon zkEVM, taking into account zkEVM's effective gas pricing.
This method accepts the same transaction call object as `eth_estimateGas`
and returns `gasUsed * estimatedGasPrice` as a hex-encoded wei value.


Reference: https://www.alchemy.com/docs/chains/polygon-zkevm/polygon-zk-evm-api-endpoints/zkevm-estimate-fee

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| transaction | object | Yes | Transaction call object (same shape as `eth_estimateGas`). |

## Result

**Estimated Fee** (string): The estimated total fee in wei as a hex-encoded quantity.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "zkevm_estimateFee",
  "params": [
    {
      "from": "0x0000000000000000000000000000000000000001",
      "to": "0x0000000000000000000000000000000000000002",
      "value": "0x186a0",
      "data": "0x"
    }
  ],
  "id": 1
}
```

### Response

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

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://polygonzkevm-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "zkevm_estimateFee",
  "params": [
    {
      "from": "0x0000000000000000000000000000000000000001",
      "to": "0x0000000000000000000000000000000000000002",
      "value": "0x186a0",
      "data": "0x"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'zkevm_estimateFee',
    params: [
      {
        from: '0x0000000000000000000000000000000000000001',
        to: '0x0000000000000000000000000000000000000002',
        value: '0x186a0',
        data: '0x'
      }
    ]
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "zkevm_estimateFee",
    "params": [
        {
            "from": "0x0000000000000000000000000000000000000001",
            "to": "0x0000000000000000000000000000000000000002",
            "value": "0x186a0",
            "data": "0x"
        }
    ]
}
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://polygonzkevm-mainnet.g.alchemy.com/v2/docs-demo"

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

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://polygonzkevm-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\": \"zkevm_estimateFee\",\n  \"params\": [\n    {\n      \"from\": \"0x0000000000000000000000000000000000000001\",\n      \"to\": \"0x0000000000000000000000000000000000000002\",\n      \"value\": \"0x186a0\",\n      \"data\": \"0x\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: zkevm_estimateFee
summary: Estimates the total transaction fee (wei) for a given transaction.
description: |
  Returns the estimated transaction fee for executing the provided transaction
  on Polygon zkEVM, taking into account zkEVM's effective gas pricing.
  This method accepts the same transaction call object as `eth_estimateGas`
  and returns `gasUsed * estimatedGasPrice` as a hex-encoded wei value.
params:
  - name: transaction
    required: true
    description: Transaction call object (same shape as `eth_estimateGas`).
    schema:
      type: object
      additionalProperties: false
      properties:
        from:
          title: hex encoded address
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
        to:
          title: hex encoded address
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
        gas:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        gasPrice:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        maxFeePerGas:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        maxPriorityFeePerGas:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        value:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        data:
          title: hex encoded bytes
          type: string
          pattern: ^0x[0-9a-f]*$
result:
  name: Estimated Fee
  description: The estimated total fee in wei as a hex-encoded quantity.
  schema:
    title: hex encoded unsigned integer
    type: string
    pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
examples:
  - name: zkevm_estimateFee example
    params:
      - name: transaction
        value:
          from: '0x0000000000000000000000000000000000000001'
          to: '0x0000000000000000000000000000000000000002'
          value: '0x186a0'
          data: 0x
    result:
      name: Estimated Fee
      value: '0x1'
```
