# starknet_estimateMessageFee

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

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

Estimates the resources required by the l1_handler transaction induced by the message.

Reference: https://www.alchemy.com/docs/chains/starknet/starknet-api-endpoints/starknet-estimate-message-fee

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| MSG_FROM_L1 | object | Yes | The Message from L1 object |
| block_id | object or enum | Yes | The hash of the requested block, the block number (height) of the requested block, or a block tag (latest or pending) |

## Result

**result** (object[]): Array of fee estimation results

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://starknet-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "starknet_estimateMessageFee",
  "params": [
    {
      "from_address": "string",
      "to_address": "string",
      "entry_point_selector": "string"
    },
    {
      "block_hash": "string"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'starknet_estimateMessageFee',
    params: [
      {from_address: 'string', to_address: 'string', entry_point_selector: 'string'},
      {block_hash: 'string'}
    ]
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "starknet_estimateMessageFee",
    "params": [{
            "from_address": "string",
            "to_address": "string",
            "entry_point_selector": "string"
        }, { "block_hash": "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://starknet-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"starknet_estimateMessageFee\",\n  \"params\": [\n    {\n      \"from_address\": \"string\",\n      \"to_address\": \"string\",\n      \"entry_point_selector\": \"string\"\n    },\n    {\n      \"block_hash\": \"string\"\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://starknet-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"starknet_estimateMessageFee\",\n  \"params\": [\n    {\n      \"from_address\": \"string\",\n      \"to_address\": \"string\",\n      \"entry_point_selector\": \"string\"\n    },\n    {\n      \"block_hash\": \"string\"\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://starknet-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\": \"starknet_estimateMessageFee\",\n  \"params\": [\n    {\n      \"from_address\": \"string\",\n      \"to_address\": \"string\",\n      \"entry_point_selector\": \"string\"\n    },\n    {\n      \"block_hash\": \"string\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: starknet_estimateMessageFee
summary: Estimates the resources required by the l1_handler transaction induced by the message.
description: Estimates the resources required by the l1_handler transaction induced by the message.
paramStructure: by-name
params:
  - name: MSG_FROM_L1
    description: The Message from L1 object
    required: true
    schema:
      type: object
      title: Message from L1
      required:
        - from_address
        - to_address
        - entry_point_selector
        - payload
      properties:
        from_address:
          type: string
          description: The address of the L1 contract sending the message
        to_address:
          type: string
          description: The target L2 address the message is sent to
        entry_point_selector:
          type: string
          description: The selector of the l1_handler in invoke in the target contract
        payload:
          type: array
          description: The payload of the message
  - name: block_id
    description: The hash of the requested block, the block number (height) of the requested block, or a block tag (latest or pending)
    required: true
    schema:
      title: Block id
      description: Block hash, number or tag
      oneOf:
        - title: Block hash
          type: object
          required:
            - block_hash
          properties:
            block_hash:
              title: Block hash
              description: The hash identifying a block
              type: string
              pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
        - title: Block number
          type: object
          required:
            - block_number
          properties:
            block_number:
              title: Block number
              description: The block's number (its height)
              type: integer
              minimum: 0
        - title: Block tag
          description: A tag specifying a dynamic reference to a block
          type: string
          enum:
            - latest
            - pending
result:
  name: result
  description: Array of fee estimation results
  schema:
    type: array
    title: Message fee estimate
    items:
      type: object
      properties:
        l1_data_gas_consumed:
          type: string
          description: The amount of Layer 1 data gas consumed by the transaction
        l1_data_gas_price:
          type: string
          description: The price per unit of Layer 1 data gas (in WEI)
        l1_gas_consumed:
          type: string
          description: The amount of Layer 1 execution gas consumed by the transaction
        l1_gas_price:
          type: string
          description: The price per unit of Layer 1 execution gas (in WEI)
        l2_gas_consumed:
          type: string
          description: The amount of Layer 2 gas consumed by the transaction
        l2_gas_price:
          type: string
          description: The price per unit of Layer 2 gas (in WEI)
        overall_fee:
          type: string
          description: The total estimated fee for the transaction in WEI, computed using all gas consumed and respective prices
        unit:
          type: string
          description: The unit in which the overall fee is expressed
```
