# zks_getL2ToL1MsgProof

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

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

Retrieves the proof for an L2 to L1 message.

Reference: https://www.alchemy.com/docs/chains/zksync/zk-sync-api-endpoints/zks-get-l-2-to-l-1-msg-proof

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| L2 block number | string | Yes | The L2 block number. |
| Sender address | string | Yes | The sender's address. |
| Message hash | string | Yes | The message hash. |
| Log position | integer | No | The log position in L2. |

## Result

**Message Proof** (object): The proof for the L2 to L1 message.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "zks_getL2ToL1MsgProof",
  "params": [
    100000,
    "0x1111111111111111111111111111111111111111",
    "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    0
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "proof": [
      "0x8c48910df2ca7de509daf50b3182fcdf2dd6c422c6704054fd857d6c9516d6fc"
    ],
    "root": "0x920c63cb0066a08da45f0a9bf934517141bd72d8e5a51421a94b517bf49a0d39",
    "id": 0
  },
  "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_getL2ToL1MsgProof",
  "params": [
    "string",
    "0x1111111111111111111111111111111111111111",
    "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    1
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'zks_getL2ToL1MsgProof',
    params: [
      'string',
      '0x1111111111111111111111111111111111111111',
      '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
      1
    ]
  })
};

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_getL2ToL1MsgProof",
    "params": ["string", "0x1111111111111111111111111111111111111111", "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1]
}
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_getL2ToL1MsgProof\",\n  \"params\": [\n    \"string\",\n    \"0x1111111111111111111111111111111111111111\",\n    \"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n    1\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_getL2ToL1MsgProof\",\n  \"params\": [\n    \"string\",\n    \"0x1111111111111111111111111111111111111111\",\n    \"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n    1\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_getL2ToL1MsgProof\",\n  \"params\": [\n    \"string\",\n    \"0x1111111111111111111111111111111111111111\",\n    \"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n    1\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: zks_getL2ToL1MsgProof
summary: Retrieves the proof for an L2 to L1 message.
description: Retrieves the proof for an L2 to L1 message.
params:
  - name: L2 block number
    required: true
    description: The L2 block number.
    schema:
      title: hex encoded 32-bit unsigned integer
      type: string
      pattern: ^0x[0-9a-fA-F]{1,8}$
  - name: Sender address
    required: true
    description: The sender's address.
    schema:
      title: hex encoded address
      type: string
      pattern: ^0x[0-9a-fA-F]{40}$
  - name: Message hash
    required: true
    description: The message hash.
    schema:
      title: 32 byte hex value
      type: string
      pattern: ^0x[0-9a-f]{64}$
  - name: Log position
    required: false
    description: The log position in L2.
    schema:
      type: integer
result:
  name: Message Proof
  description: The proof for the L2 to L1 message.
  schema:
    type: object
    title: Message Proof
    required:
      - proof
      - root
      - id
    properties:
      proof:
        type: array
        description: Array of strings, each representing a piece of the proof.
        items:
          title: 32 byte hex value
          type: string
          pattern: ^0x[0-9a-f]{64}$
      root:
        title: 32 byte hex value
        type: string
        pattern: ^0x[0-9a-f]{64}$
        description: Root hash of the proof.
      id:
        type: integer
        description: Identifier of the message within the block.
examples:
  - name: zks_getL2ToL1MsgProof example
    params:
      - name: L2 block number
        value: 100000
      - name: Sender address
        value: '0x1111111111111111111111111111111111111111'
      - name: Message hash
        value: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
      - name: Log position
        value: 0
    result:
      name: Message Proof
      value:
        proof:
          - '0x8c48910df2ca7de509daf50b3182fcdf2dd6c422c6704054fd857d6c9516d6fc'
        root: '0x920c63cb0066a08da45f0a9bf934517141bd72d8e5a51421a94b517bf49a0d39'
        id: 0
```
