# getProgramAccounts

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

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

Returns all accounts owned by the provided program Pubkey.

Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/get-program-accounts

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Pubkey | string | Yes | The Pubkey of the program. |
| Configuration | object | No | Optional configuration object. |

## Result

**Program accounts** (object[]): An array of JSON objects containing program account details.

## 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": "getProgramAccounts",
  "params": [
    "string",
    {
      "commitment": "processed",
      "minContextSlot": 1,
      "withContext": false,
      "encoding": "base58",
      "dataSlice": {
        "length": 1,
        "offset": 1
      }
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getProgramAccounts',
    params: [
      'string',
      {
        commitment: 'processed',
        minContextSlot: 1,
        withContext: false,
        encoding: 'base58',
        dataSlice: {length: 1, offset: 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": "getProgramAccounts",
    "params": [
        "string",
        {
            "commitment": "processed",
            "minContextSlot": 1,
            "withContext": False,
            "encoding": "base58",
            "dataSlice": {
                "length": 1,
                "offset": 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\": \"getProgramAccounts\",\n  \"params\": [\n    \"string\",\n    {\n      \"commitment\": \"processed\",\n      \"minContextSlot\": 1,\n      \"withContext\": false,\n      \"encoding\": \"base58\",\n      \"dataSlice\": {\n        \"length\": 1,\n        \"offset\": 1\n      }\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\": \"getProgramAccounts\",\n  \"params\": [\n    \"string\",\n    {\n      \"commitment\": \"processed\",\n      \"minContextSlot\": 1,\n      \"withContext\": false,\n      \"encoding\": \"base58\",\n      \"dataSlice\": {\n        \"length\": 1,\n        \"offset\": 1\n      }\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\": \"getProgramAccounts\",\n  \"params\": [\n    \"string\",\n    {\n      \"commitment\": \"processed\",\n      \"minContextSlot\": 1,\n      \"withContext\": false,\n      \"encoding\": \"base58\",\n      \"dataSlice\": {\n        \"length\": 1,\n        \"offset\": 1\n      }\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getProgramAccounts
description: Returns all accounts owned by the provided program Pubkey.
params:
  - name: Pubkey
    required: true
    description: The Pubkey of the program.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: Configuration
    required: false
    description: Optional configuration object.
    schema:
      title: GetProgramAccounts Configuration
      type: object
      properties:
        commitment:
          title: Commitment Level
          type: string
          description: Configures the state commitment for querying.
          enum:
            - processed
            - confirmed
            - finalized
        minContextSlot:
          title: Minimum Context Slot
          type: integer
          description: The minimum slot that the request can be evaluated at.
        withContext:
          type: boolean
          description: If set, wraps the result in an `RpcResponse` JSON object.
        encoding:
          default: json
          title: Data Encoding
          type: string
          description: Encoding format for data.
          enum:
            - base58
            - base64
            - base64+zstd
            - jsonParsed
        dataSlice:
          title: Data Slice
          type: object
          properties:
            length:
              type: integer
              description: Number of bytes to return.
            offset:
              type: integer
              description: Byte offset from which to start reading.
        filters:
          type: array
          description: Filters to apply using up to 4 filter objects.
result:
  name: Program accounts
  description: An array of JSON objects containing program account details.
  schema:
    type: array
    items:
      title: Program Account
      type: object
      properties:
        pubkey:
          title: Pubkey
          type: string
          description: The account Pubkey as a base-58 encoded string.
        account:
          title: Account Information
          type: object
          properties:
            lamports:
              type: integer
              description: Number of lamports assigned to this account.
            owner:
              title: Pubkey
              type: string
              description: Program owner of this account.
            data:
              title: Account Data
              type: array
              description: Account data in the specified encoding format.
              items:
                type: string
            executable:
              type: boolean
              description: Indicates if the account contains a program.
            rentEpoch:
              type: integer
              description: The epoch at which this account will next owe rent.
            size:
              type: integer
              description: The data size of the account.
```
