# getValidityProof

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

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

Returns a single ZK validity proof for the given compressed account hashes and/or new addresses.

Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/get-validity-proof

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Configuration | object | Yes | Compressed account hashes to prove inclusion for and/or new addresses to prove non-inclusion for. |

## Result

**Validity proof** (object): A ZK validity proof with context for inclusion and non-inclusion claims.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getValidityProof",
  "params": [
    {
      "hashes": [
        "11111111111111111111111111111111"
      ],
      "newAddressesWithTrees": []
    }
  ],
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://solana-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getValidityProof",
  "params": [
    {
      "hashes": [
        "11111111111111111111111111111111"
      ],
      "newAddressesWithTrees": []
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getValidityProof',
    params: [{hashes: ['11111111111111111111111111111111'], newAddressesWithTrees: []}]
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getValidityProof",
    "params": [
        {
            "hashes": ["11111111111111111111111111111111"],
            "newAddressesWithTrees": []
        }
    ]
}
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://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getValidityProof\",\n  \"params\": [\n    {\n      \"hashes\": [\n        \"11111111111111111111111111111111\"\n      ],\n      \"newAddressesWithTrees\": []\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://solana-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getValidityProof\",\n  \"params\": [\n    {\n      \"hashes\": [\n        \"11111111111111111111111111111111\"\n      ],\n      \"newAddressesWithTrees\": []\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-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\": \"getValidityProof\",\n  \"params\": [\n    {\n      \"hashes\": [\n        \"11111111111111111111111111111111\"\n      ],\n      \"newAddressesWithTrees\": []\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getValidityProof
description: Returns a single ZK validity proof for the given compressed account hashes and/or new addresses.
params:
  - name: Configuration
    required: true
    description: Compressed account hashes to prove inclusion for and/or new addresses to prove non-inclusion for.
    schema:
      title: getValidityProof Params
      type: object
      properties:
        hashes:
          type: array
          items:
            title: Hash
            type: string
            description: A 32-byte hash represented as a base-58 string.
        newAddressesWithTrees:
          type: array
          items:
            title: Address With Tree
            type: object
            properties:
              address:
                title: Pubkey
                type: string
                description: Base-58 encoded public key.
              tree:
                title: Pubkey
                type: string
                description: Base-58 encoded public key.
examples:
  - name: getValidityProof example
    params:
      - name: Configuration
        value:
          hashes:
            - '11111111111111111111111111111111'
          newAddressesWithTrees: []
result:
  name: Validity proof
  description: A ZK validity proof with context for inclusion and non-inclusion claims.
  schema:
    title: Validity Proof Result
    type: object
    properties:
      context:
        title: Compression Context
        type: object
        properties:
          slot:
            type: integer
            description: The slot at which the response was generated.
      value:
        title: Validity Proof With Context
        type: object
        properties:
          compressedProof:
            title: Compressed Proof
            type: object
            properties:
              a:
                type: array
                items:
                  type: integer
              b:
                type: array
                items:
                  type: integer
              c:
                type: array
                items:
                  type: integer
          roots:
            type: array
            items:
              type: string
          rootIndices:
            type: array
            items:
              type: integer
          leafIndices:
            type: array
            items:
              type: integer
          leaves:
            type: array
            items:
              type: string
          merkleTrees:
            type: array
            items:
              type: string
```
