165 lines
4.1 KiB
Plaintext
165 lines
4.1 KiB
Plaintext
import {
|
|
DocBlock,
|
|
DocSideBySide,
|
|
CodeParams,
|
|
Parameter,
|
|
Field,
|
|
Values,
|
|
CodeSnippets,
|
|
} from "../../../components/CodeDocBlock";
|
|
|
|
<DocBlock>
|
|
|
|
## getProgramAccounts
|
|
|
|
Returns all accounts owned by the provided program Pubkey
|
|
|
|
<DocSideBySide>
|
|
<CodeParams>
|
|
|
|
### Parameters:
|
|
|
|
<Parameter type={"string"} required={true}>
|
|
Pubkey of program, as base-58 encoded string
|
|
</Parameter>
|
|
|
|
<Parameter type={"object"} optional={true}>
|
|
|
|
Configuration object containing the following fields:
|
|
|
|
<Field
|
|
name="commitment"
|
|
type="string"
|
|
optional={true}
|
|
href="/api/http#configuring-state-commitment"
|
|
></Field>
|
|
|
|
<Field name="minContextSlot" type="number" optional={true}>
|
|
The minimum slot that the request can be evaluated at
|
|
</Field>
|
|
|
|
<Field name="withContext" type="bool" optional={true}>
|
|
wrap the result in an RpcResponse JSON object
|
|
</Field>
|
|
|
|
<Field name="encoding" type="string" optional={true} defaultValue={"json"} href="/api/http#parsed-responses">
|
|
|
|
encoding format for the returned Account data
|
|
|
|
<Values values={["jsonParsed", "base58", "base64", "base64+zstd"]} />
|
|
|
|
<details>
|
|
|
|
- `base58` is slow and limited to less than 129 bytes of Account data.
|
|
- `base64` will return base64 encoded data for Account data of any size.
|
|
- `base64+zstd` compresses the Account data using [Zstandard](https://facebook.github.io/zstd/) and
|
|
base64-encodes the result.
|
|
- [`jsonParsed` encoding](/api/http#parsed-responses) attempts to use program-specific state
|
|
parsers to return more human-readable and explicit account state data.
|
|
- If `jsonParsed` is requested but a parser cannot be found, the field falls back
|
|
to `base64` encoding, detectable when the `data` field is type `<string>`.
|
|
|
|
</details>
|
|
|
|
</Field>
|
|
|
|
<Field name="dataSlice" type="object" optional={true}>
|
|
Request a slice of the account's data.
|
|
|
|
- `length: <usize>` - number of bytes to return
|
|
- `offset: <usize>` - byte offset from which to start reading
|
|
|
|
:::info
|
|
Data slicing is only available for <code>base58</code>, <code>base64</code>, or <code>base64+zstd</code> encodings.
|
|
:::
|
|
</Field>
|
|
|
|
<Field name="filters" type="array" optional={true} href={"/api/http#filter-criteria"}>
|
|
|
|
filter results using up to 4 filter objects
|
|
|
|
:::info
|
|
The resultant account(s) must meet **ALL** filter criteria to be included in the returned results
|
|
:::
|
|
|
|
</Field>
|
|
|
|
</Parameter>
|
|
|
|
### Result:
|
|
|
|
By default, the result field will be an array of JSON objects.
|
|
|
|
:::info
|
|
If `withContext` flag is set the array will be wrapped in an RpcResponse JSON object.
|
|
:::
|
|
|
|
The resultant response array will contain:
|
|
|
|
- `pubkey: <string>` - the account Pubkey as base-58 encoded string
|
|
- `account: <object>` - a JSON object, with the following sub fields:
|
|
- `lamports: <u64>` - number of lamports assigned to this account, as a u64
|
|
- `owner: <string>` - base-58 encoded Pubkey of the program this account has been assigned to
|
|
- `data: <[string,encoding]|object>` - data associated with the account, either as encoded binary data or JSON format `{<program>: <state>}` - depending on encoding parameter
|
|
- `executable: <bool>` - boolean indicating if the account contains a program \(and is strictly read-only\)
|
|
- `rentEpoch: <u64>` - the epoch at which this account will next owe rent, as u64
|
|
- `size: <u64>` - the data size of the account
|
|
|
|
</CodeParams>
|
|
|
|
<CodeSnippets>
|
|
|
|
### Code sample:
|
|
|
|
```bash
|
|
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
|
|
{
|
|
"jsonrpc": "2.0",
|
|
"id": 1,
|
|
"method": "getProgramAccounts",
|
|
"params": [
|
|
"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
|
|
{
|
|
"filters": [
|
|
{
|
|
"dataSize": 17
|
|
},
|
|
{
|
|
"memcmp": {
|
|
"offset": 4,
|
|
"bytes": "3Mc6vR"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
'
|
|
```
|
|
|
|
### Response:
|
|
|
|
```json
|
|
{
|
|
"jsonrpc": "2.0",
|
|
"result": [
|
|
{
|
|
"account": {
|
|
"data": "2R9jLfiAQ9bgdcw6h8s44439",
|
|
"executable": false,
|
|
"lamports": 15298080,
|
|
"owner": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
|
|
"rentEpoch": 28,
|
|
"space": 42
|
|
},
|
|
"pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
|
|
}
|
|
],
|
|
"id": 1
|
|
}
|
|
```
|
|
|
|
</CodeSnippets>
|
|
</DocSideBySide>
|
|
</DocBlock>
|