# getCompressedAccountsByOwner

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

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

Returns the compressed accounts owned by the given Pubkey.

Advanced filters (`dataSlice`, `filters`) are supported by the underlying Photon API but are not modeled in this Try It widget. To use them, send the request directly with `dataSlice: { offset, length }` and/or `filters: [{ memcmp: { offset, bytes } }]` added to the `params` object.


Reference: https://www.alchemy.com/docs/chains/solana/solana-photon-api/solana-photon-api/get-compressed-accounts-by-owner

## Parameters

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

## Result

**Compressed accounts** (object): A paginated list of compressed accounts owned by the given Pubkey.

## Example

### Request

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

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 418890736
    },
    "value": {
      "items": [
        {
          "hash": "2U9KV9sCU5MtJaDTKVkuuEbagVEBL9BQSfUBsaiEP6Cf",
          "address": null,
          "data": null,
          "owner": "bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW",
          "lamports": 1855202212,
          "tree": "smt4vjXvdjDFzvRMUxwTWnSy4c7cKkMaHuPrGsdDH7V",
          "leafIndex": 838169,
          "seq": 884595,
          "slotCreated": 357735567
        }
      ],
      "cursor": "2U9KV9sCU5MtJaDTKVkuuEbagVEBL9BQSfUBsaiEP6Cf"
    }
  },
  "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": "getCompressedAccountsByOwner",
  "params": [
    "bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW",
    "string",
    1
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getCompressedAccountsByOwner',
    params: ['bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW', '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": "getCompressedAccountsByOwner",
    "params": ["bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW", "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\": \"getCompressedAccountsByOwner\",\n  \"params\": [\n    \"bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW\",\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\": \"getCompressedAccountsByOwner\",\n  \"params\": [\n    \"bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW\",\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\": \"getCompressedAccountsByOwner\",\n  \"params\": [\n    \"bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW\",\n    \"string\",\n    1\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getCompressedAccountsByOwner
description: |
  Returns the compressed accounts owned by the given Pubkey.

  Advanced filters (`dataSlice`, `filters`) are supported by the underlying Photon API but are not modeled in this Try It widget. To use them, send the request directly with `dataSlice: { offset, length }` and/or `filters: [{ memcmp: { offset, bytes } }]` added to the `params` object.
paramStructure: by-name
x-compute-units: 120
x-rate-limit-cus: 100
params:
  - name: owner
    required: true
    description: Pubkey of the owner whose compressed accounts to query.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: cursor
    required: false
    description: Pagination cursor returned by a previous response.
    schema:
      oneOf:
        - title: Hash
          type: string
          description: A 32-byte hash represented as a base-58 string.
        - type: 'null'
  - name: limit
    required: false
    description: Maximum number of accounts to return.
    schema:
      oneOf:
        - title: Limit
          type: integer
          description: Maximum number of items to return.
        - type: 'null'
examples:
  - name: getCompressedAccountsByOwner example
    params:
      - name: owner
        value: bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW
      - name: limit
        value: 1
    result:
      name: Compressed accounts
      value:
        context:
          slot: 418890736
        value:
          items:
            - hash: 2U9KV9sCU5MtJaDTKVkuuEbagVEBL9BQSfUBsaiEP6Cf
              address: null
              data: null
              owner: bukwBg6C8VAHsuak1dPm5Teiu3eWe78xakgTL8QjVbW
              lamports: 1855202212
              tree: smt4vjXvdjDFzvRMUxwTWnSy4c7cKkMaHuPrGsdDH7V
              leafIndex: 838169
              seq: 884595
              slotCreated: 357735567
          cursor: 2U9KV9sCU5MtJaDTKVkuuEbagVEBL9BQSfUBsaiEP6Cf
result:
  name: Compressed accounts
  description: A paginated list of compressed accounts owned by the given Pubkey.
  schema:
    title: Paginated Compressed Account 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: Paginated Compressed Account List
        type: object
        properties:
          cursor:
            title: Hash
            type: string
            description: A 32-byte hash represented as a base-58 string.
          items:
            type: array
            items:
              title: Compressed Account
              type: object
              properties:
                address:
                  title: Pubkey
                  type: string
                  description: Base-58 encoded public key.
                data:
                  title: Compressed Account Data
                  type: object
                  properties:
                    discriminator:
                      title: Unsigned Integer
                      type: integer
                      description: An unsigned 64-bit integer.
                    data:
                      title: Base64 String
                      type: string
                      description: A base-64 encoded string.
                    dataHash:
                      title: Hash
                      type: string
                      description: A 32-byte hash represented as a base-58 string.
                hash:
                  title: Hash
                  type: string
                  description: A 32-byte hash represented as a base-58 string.
                lamports:
                  title: Unsigned Integer
                  type: integer
                  description: An unsigned 64-bit integer.
                leafIndex:
                  title: Unsigned Integer
                  type: integer
                  description: An unsigned 64-bit integer.
                owner:
                  title: Pubkey
                  type: string
                  description: Base-58 encoded public key.
                seq:
                  title: Unsigned Integer
                  type: integer
                  description: An unsigned 64-bit integer.
                slotCreated:
                  title: Unsigned Integer
                  type: integer
                  description: An unsigned 64-bit integer.
                tree:
                  title: Pubkey
                  type: string
                  description: Base-58 encoded public key.
```
