# getCompressedTokenBalancesByOwner

> 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-photon-api/solana-photon-api/get-compressed-token-balances-by-owner

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| owner | string | Yes | Pubkey of the owner whose compressed token balances to query. |
| mint | string or null | No | Optional mint Pubkey to filter balances by. |
| cursor | string or null | No | Pagination cursor returned by a previous response. |
| limit | integer or null | No | Maximum number of balances to return. |

## Result

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

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getCompressedTokenBalancesByOwner",
  "params": [
    "bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 418485622
    },
    "value": {
      "token_balances": [
        {
          "mint": "5iVmFCCwJTuuw7p4FrxYoZ1bUNdjg14j7uv5hMsMpump",
          "balance": 108197404958
        },
        {
          "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
          "balance": 581283412
        }
      ],
      "cursor": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
    }
  },
  "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": "getCompressedTokenBalancesByOwner",
  "params": [
    "bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW",
    "string",
    "string",
    1
  ]
}'
```

### JavaScript

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

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": "getCompressedTokenBalancesByOwner",
    "params": ["bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW", "string", "string", 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://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getCompressedTokenBalancesByOwner\",\n  \"params\": [\n    \"bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW\",\n    \"string\",\n    \"string\",\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://solana-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getCompressedTokenBalancesByOwner\",\n  \"params\": [\n    \"bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW\",\n    \"string\",\n    \"string\",\n    1\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\": \"getCompressedTokenBalancesByOwner\",\n  \"params\": [\n    \"bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW\",\n    \"string\",\n    \"string\",\n    1\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getCompressedTokenBalancesByOwner
description: Returns the compressed token balances for the given Pubkey.
paramStructure: by-name
x-compute-units: 120
x-rate-limit-cus: 100
params:
  - name: owner
    required: true
    description: Pubkey of the owner whose compressed token balances to query.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: mint
    required: false
    description: Optional mint Pubkey to filter balances by.
    schema:
      oneOf:
        - title: Pubkey
          type: string
          description: Base-58 encoded public key.
        - type: 'null'
  - name: cursor
    required: false
    description: Pagination cursor returned by a previous response.
    schema:
      oneOf:
        - title: Base58 String
          type: string
          description: A base-58 encoded string.
        - type: 'null'
  - name: limit
    required: false
    description: Maximum number of balances to return.
    schema:
      oneOf:
        - title: Limit
          type: integer
          description: Maximum number of items to return.
        - type: 'null'
examples:
  - name: getCompressedTokenBalancesByOwner example
    params:
      - name: owner
        value: bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW
    result:
      name: Compressed token balances
      value:
        context:
          slot: 418485622
        value:
          token_balances:
            - mint: 5iVmFCCwJTuuw7p4FrxYoZ1bUNdjg14j7uv5hMsMpump
              balance: 108197404958
            - mint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
              balance: 581283412
          cursor: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
result:
  name: Compressed token balances
  description: A paginated list of compressed token balances for the owner.
  schema:
    title: Compressed Token Balance List 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: Compressed Token Balance List
        type: object
        properties:
          cursor:
            title: Base58 String
            type: string
            description: A base-58 encoded string.
          token_balances:
            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.
```
