Skip to content

Commit b51149d

Browse files
add shit
1 parent 391d36c commit b51149d

File tree

4 files changed

+330
-174
lines changed

4 files changed

+330
-174
lines changed

api-reference/rpc/http/getprogramaccountsv2.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ openapi: "/openapi/rpc-http/getProgramAccountsV2.yaml POST /"
1717
- **Incremental updates**: Use `changedSinceSlot` to fetch only recently modified accounts
1818
- **Better performance**: Prevents timeouts and reduces memory usage for large datasets
1919
- **Backward compatibility**: Supports all existing `getProgramAccounts` parameters
20+
- **Optional `withContext`**: Request snapshot metadata (`slot`, `apiVersion`) in a standard Solana-style wrapped `result`
2021
</Info>
2122

2223
## Key Benefits
@@ -109,6 +110,32 @@ const incrementalUpdate = await fetch(`https://mainnet.helius-rpc.com/?api-key=$
109110
- **Store `paginationKey`** to resume queries if interrupted
110111
- **Monitor response times** and adjust limits accordingly
111112

113+
## `withContext` (optional)
114+
115+
`withContext` is a boolean on the configuration object (alongside `encoding`, `limit`, `filters`, and so on). It only changes the JSON shape of `result`, not filters, limits, or pagination behavior.
116+
117+
- **Omitted or `false`**: The paginated payload is returned directly on `result` — read `result.accounts`, `result.paginationKey`, and `result.totalResults` (when present).
118+
- **`true`**: The RPC returns the standard Solana wrapped shape: `result.context` (snapshot metadata, including `slot` and usually `apiVersion`) and the same payload under `result.value` — read `result.value.accounts`, `result.value.paginationKey`, and `result.value.totalResults`.
119+
120+
```json
121+
// withContext omitted or false
122+
{ "jsonrpc": "2.0", "id": "1", "result": {
123+
"accounts": [],
124+
"paginationKey": null,
125+
"totalResults": null
126+
}}
127+
128+
// withContext: true
129+
{ "jsonrpc": "2.0", "id": "1", "result": {
130+
"context": { "slot": 411895550, "apiVersion": "3.1.9" },
131+
"value": { "accounts": [], "paginationKey": null, "totalResults": null }
132+
}}
133+
```
134+
135+
<Note>
136+
**Client parsing**: If `withContext` is `false` or missing, use `result.accounts` (and `paginationKey`, `totalResults`). If `withContext` is `true`, use `result.value.accounts` (and `result.value.paginationKey`, `result.value.totalResults`) and read `result.context.slot` (and `apiVersion`) when you need snapshot consistency or debugging.
137+
</Note>
138+
112139
## Migration from getProgramAccounts
113140

114141
Migrating from the original method is straightforward - simply replace the method name and add pagination parameters:
@@ -159,7 +186,7 @@ Migrating from the original method is straightforward - simply replace the metho
159186
</ParamField>
160187

161188
<ParamField body="withContext" type="boolean">
162-
Wrap the result in an RpcResponse JSON object.
189+
When `true`, nests `accounts`, `paginationKey`, and `totalResults` under `result.value` and adds `result.context` (`slot`, `apiVersion`). When `false` or omitted, those fields are on `result` directly (for example `result.accounts`). Same query semantics as without this flag.
163190
</ParamField>
164191

165192
<ParamField body="encoding" type="string">

api-reference/rpc/http/gettokenaccountsbyownerv2.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ openapi: "/openapi/rpc-http/getTokenAccountsByOwnerV2.yaml POST /"
1717
- **Incremental updates**: Use `changedSinceSlot` to fetch only recently modified token accounts
1818
- **Portfolio scalability**: Handle wallets with thousands of token accounts efficiently
1919
- **Backward compatibility**: Supports all existing `getTokenAccountsByOwner` parameters and filters
20+
- **Optional `withContext`**: Request snapshot metadata (`slot`, `apiVersion`) in a standard Solana-style wrapped `result`
2021
</Info>
2122

2223
<Warning>
@@ -34,6 +35,39 @@ openapi: "/openapi/rpc-http/getTokenAccountsByOwnerV2.yaml POST /"
3435
</Card>
3536
</CardGroup>
3637

38+
## `withContext` (optional)
39+
40+
`withContext` is a boolean on the configuration object (third parameter — alongside `encoding`, `limit`, and so on). It only changes the JSON shape of `result`, not filters, limits, or pagination behavior.
41+
42+
- **Omitted or `false`**: Matches the familiar shape: the token account list for the page is **`result.value` as an array**, with `result.paginationKey` and `result.totalResults` on `result`.
43+
- **`true`**: The RPC returns the wrapped shape: **`result.context`** (snapshot metadata, including `slot` and usually `apiVersion`) and **`result.value` as an object** with `accounts`, `paginationKey`, and `totalResults`.
44+
45+
```json
46+
// withContext omitted or false
47+
{ "jsonrpc": "2.0", "id": "1", "result": {
48+
"value": [],
49+
"paginationKey": null,
50+
"totalResults": null
51+
}}
52+
53+
// withContext: true
54+
{ "jsonrpc": "2.0", "id": "1", "result": {
55+
"context": { "slot": 411895550, "apiVersion": "3.1.9" },
56+
"value": { "accounts": [], "paginationKey": null, "totalResults": null }
57+
}}
58+
```
59+
60+
When you support both modes, resolve the account list with:
61+
62+
```typescript
63+
const accounts = Array.isArray(data.result.value)
64+
? data.result.value
65+
: data.result.value.accounts;
66+
const nextKey = Array.isArray(data.result.value)
67+
? data.result.paginationKey
68+
: data.result.value.paginationKey;
69+
```
70+
3771
## Pagination Best Practices
3872

3973
<Warning>
@@ -180,6 +214,10 @@ Migration is simple - just add pagination parameters to your existing queries:
180214
The minimum slot that the request can be evaluated at.
181215
</ParamField>
182216

217+
<ParamField body="withContext" type="boolean">
218+
When `true`, returns `result.context` (`slot`, `apiVersion`) and nests `accounts`, `paginationKey`, and `totalResults` under `result.value` as an object. When `false` or omitted, `result.value` is the token account array for this page, with `paginationKey` and `totalResults` on `result`. Same query semantics as without this flag.
219+
</ParamField>
220+
183221
<ParamField body="dataSlice" type="object">
184222
Request a slice of the account's data.
185223
</ParamField>

openapi/rpc-http/getProgramAccountsV2.yaml

Lines changed: 95 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,66 @@ components:
4545
type: string
4646
description: Identifier matching the request.
4747
example: "1"
48+
ProgramAccountV2Entry:
49+
type: object
50+
properties:
51+
pubkey:
52+
type: string
53+
description: The account Pubkey as a base-58 encoded string.
54+
example: "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
55+
account:
56+
type: object
57+
description: Details about the account.
58+
properties:
59+
lamports:
60+
type: integer
61+
description: Number of lamports assigned to this account.
62+
example: 15298080
63+
owner:
64+
type: string
65+
description: Base-58 encoded Pubkey of the program this account is assigned to.
66+
example: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
67+
data:
68+
type: array
69+
description: Account data as encoded binary or JSON format.
70+
items:
71+
type: string
72+
example:
73+
- "2R9jLfiAQ9bgdcw6h8s44439"
74+
- base64
75+
executable:
76+
type: boolean
77+
description: Indicates if the account contains a program.
78+
example: false
79+
rentEpoch:
80+
type: integer
81+
description: The epoch at which this account will next owe rent.
82+
example: 28
83+
space:
84+
type: integer
85+
description: The data size of the account.
86+
example: 165
87+
ProgramAccountsV2Page:
88+
type: object
89+
description: >-
90+
Paginated program accounts. Same fields appear on result when withContext is false or omitted,
91+
or under result.value when withContext is true.
92+
properties:
93+
accounts:
94+
type: array
95+
description: List of program accounts for the current page.
96+
items:
97+
$ref: '#/components/schemas/ProgramAccountV2Entry'
98+
paginationKey:
99+
type: string
100+
description: Pagination cursor for the next page. Null only when no accounts are returned (end of pagination). Note that fewer accounts than the limit may be returned due to filtering, but this does not indicate end of pagination.
101+
example: "8WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
102+
nullable: true
103+
totalResults:
104+
type: integer
105+
description: Total number of accounts matching the query (if available).
106+
example: 25000
107+
nullable: true
48108
paths:
49109
/:
50110
post:
@@ -62,6 +122,13 @@ paths:
62122
63123
Note: End of pagination is only indicated when no accounts are returned. The API may return fewer accounts
64124
than the limit due to filtering - continue pagination until paginationKey is null.
125+
126+
**withContext**: Optional boolean on the configuration object (alongside encoding, limit, and so on). When
127+
`withContext` is `true`, the RPC returns the standard Solana wrapped shape: `result.context` (snapshot
128+
metadata, including `slot` and usually `apiVersion`) and `result.value` holding `accounts`, `paginationKey`,
129+
and `totalResults`. When `withContext` is `false` or omitted, those fields are returned directly on `result`
130+
(for example `result.accounts`). Filters, limits, and pagination behavior are unchanged; only the JSON shape
131+
of `result` differs.
65132
security:
66133
- ApiKeyQuery: []
67134
requestBody:
@@ -121,7 +188,10 @@ paths:
121188
example: 1000
122189
withContext:
123190
type: boolean
124-
description: Wrap the result in an RpcResponse JSON object.
191+
description: |
192+
When `true`, returns `result.context` (snapshot metadata: `slot`, `apiVersion`) and nests
193+
`accounts`, `paginationKey`, and `totalResults` under `result.value`. When `false` or omitted,
194+
those fields appear directly on `result` (for example `result.accounts`). Same filters and limits apply.
125195
example: true
126196
encoding:
127197
type: string
@@ -204,61 +274,30 @@ paths:
204274
description: Identifier matching the request.
205275
example: "1"
206276
result:
207-
type: object
208-
description: Paginated program accounts with navigation metadata.
209-
properties:
210-
accounts:
211-
type: array
212-
description: List of program accounts for the current page.
213-
items:
214-
type: object
215-
properties:
216-
pubkey:
217-
type: string
218-
description: The account Pubkey as a base-58 encoded string.
219-
example: "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
220-
account:
221-
type: object
222-
description: Details about the account.
223-
properties:
224-
lamports:
225-
type: integer
226-
description: Number of lamports assigned to this account.
227-
example: 15298080
228-
owner:
229-
type: string
230-
description: Base-58 encoded Pubkey of the program this account is assigned to.
231-
example: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
232-
data:
233-
type: array
234-
description: Account data as encoded binary or JSON format.
235-
items:
236-
type: string
237-
example:
238-
- "2R9jLfiAQ9bgdcw6h8s44439"
239-
- base64
240-
executable:
241-
type: boolean
242-
description: Indicates if the account contains a program.
243-
example: false
244-
rentEpoch:
245-
type: integer
246-
description: The epoch at which this account will next owe rent.
247-
example: 28
248-
space:
249-
type: integer
250-
description: The data size of the account.
251-
example: 165
252-
paginationKey:
253-
type: string
254-
description: Pagination cursor for the next page. Null only when no accounts are returned (end of pagination). Note that fewer accounts than the limit may be returned due to filtering, but this does not indicate end of pagination.
255-
example: "8WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
256-
nullable: true
257-
totalResults:
258-
type: integer
259-
description: Total number of accounts matching the query (if available).
260-
example: 25000
261-
nullable: true
277+
oneOf:
278+
- $ref: '#/components/schemas/ProgramAccountsV2Page'
279+
title: without withContext
280+
- type: object
281+
title: with withContext
282+
description: Wrapped result when `withContext` is `true` in the request options.
283+
required:
284+
- context
285+
- value
286+
properties:
287+
context:
288+
type: object
289+
description: Snapshot metadata for the node response (slot consistency, debugging).
290+
properties:
291+
slot:
292+
type: integer
293+
description: Slot at which the node built this response.
294+
example: 411895550
295+
apiVersion:
296+
type: string
297+
description: RPC API version when available.
298+
example: "3.1.9"
299+
value:
300+
$ref: '#/components/schemas/ProgramAccountsV2Page'
262301
400:
263302
description: Bad Request - Invalid request parameters or malformed request.
264303
content:

0 commit comments

Comments
 (0)