# getCompressedTokenBalancesByOwnerV2

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

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

Returns the compressed token balances for the given Pubkey.

Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/get-compressed-token-balances-by-owner-v-2

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Configuration | object | Yes | Owner Pubkey and optional mint filter and pagination settings. |

## Result

**Compressed token balances** (object): A paginated list of compressed token balances for the owner.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getCompressedTokenBalancesByOwnerV2",
  "params": [
    {
      "owner": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP"
    }
  ],
  "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": "getCompressedTokenBalancesByOwnerV2",
  "params": [
    {
      "owner": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP"
    }
  ]
}'
```

### JavaScript

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

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": "getCompressedTokenBalancesByOwnerV2",
    "params": [{ "owner": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP" }]
}
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\": \"getCompressedTokenBalancesByOwnerV2\",\n  \"params\": [\n    {\n      \"owner\": \"11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP\"\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\": \"getCompressedTokenBalancesByOwnerV2\",\n  \"params\": [\n    {\n      \"owner\": \"11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP\"\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\": \"getCompressedTokenBalancesByOwnerV2\",\n  \"params\": [\n    {\n      \"owner\": \"11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getCompressedTokenBalancesByOwnerV2
description: Returns the compressed token balances for the given Pubkey.
params:
  - name: Configuration
    required: true
    description: Owner Pubkey and optional mint filter and pagination settings.
    schema:
      title: getCompressedTokenBalancesByOwner Params
      type: object
      required:
        - owner
      properties:
        owner:
          title: Pubkey
          type: string
          description: Base-58 encoded public key.
        mint:
          title: Pubkey
          type: string
          description: Base-58 encoded public key.
          nullable: true
        cursor:
          title: Base58 String
          type: string
          description: A base-58 encoded string.
          nullable: true
        limit:
          nullable: true
          title: Limit
          type: integer
          description: Maximum number of items to return.
examples:
  - name: getCompressedTokenBalancesByOwnerV2 example
    params:
      - name: Configuration
        value:
          owner: 11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP
result:
  name: Compressed token balances
  description: A paginated list of compressed token balances for the owner.
  schema:
    title: Compressed Token Balance List Result (V2)
    type: object
    properties:
      context:
        title: Compression Context
        type: object
        properties:
          slot:
            type: integer
            description: The slot at which the response was generated.
      value:
        title: Compressed Token Balance List (V2)
        type: object
        properties:
          cursor:
            title: Base58 String
            type: string
            description: A base-58 encoded string.
          items:
            type: array
            items:
              title: Compressed Token Balance
              type: object
              properties:
                mint:
                  title: Pubkey
                  type: string
                  description: Base-58 encoded public key.
                balance:
                  title: Unsigned Integer
                  type: integer
                  description: An unsigned 64-bit integer.
```
