You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Store `paginationKey`** to resume queries if interrupted
110
111
-**Monitor response times** and adjust limits accordingly
111
112
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`.
**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
+
112
139
## Migration from getProgramAccounts
113
140
114
141
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
159
186
</ParamField>
160
187
161
188
<ParamFieldbody="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.
Copy file name to clipboardExpand all lines: api-reference/rpc/http/gettokenaccountsbyownerv2.mdx
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ openapi: "/openapi/rpc-http/getTokenAccountsByOwnerV2.yaml POST /"
17
17
-**Incremental updates**: Use `changedSinceSlot` to fetch only recently modified token accounts
18
18
-**Portfolio scalability**: Handle wallets with thousands of token accounts efficiently
19
19
-**Backward compatibility**: Supports all existing `getTokenAccountsByOwner` parameters and filters
20
+
-**Optional `withContext`**: Request snapshot metadata (`slot`, `apiVersion`) in a standard Solana-style wrapped `result`
20
21
</Info>
21
22
22
23
<Warning>
@@ -34,6 +35,39 @@ openapi: "/openapi/rpc-http/getTokenAccountsByOwnerV2.yaml POST /"
34
35
</Card>
35
36
</CardGroup>
36
37
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`.
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
+
37
71
## Pagination Best Practices
38
72
39
73
<Warning>
@@ -180,6 +214,10 @@ Migration is simple - just add pagination parameters to your existing queries:
180
214
The minimum slot that the request can be evaluated at.
181
215
</ParamField>
182
216
217
+
<ParamFieldbody="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.
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.
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.
0 commit comments