state_getKeysPaged
Description
Retrieves storage keys for a given prefix in pages. Ideal for scanning large maps such as System.Account
, SALP voucher registries, or omnipool asset lists.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
prefix | string | Yes | Hex-encoded storage key prefix |
count | number | Yes | Maximum number of keys to return |
startKey | string | No | Start key for pagination |
blockHash | string | No | Block hash for historical queries |
Returns
Array of up to count
storage keys.
Request Example
{
"jsonrpc": "2.0",
"method": "state_getKeysPaged",
"params": [
"0x26aa394eea5630e07c48ae0c9558cef7",
100,
null
],
"id": 1
}
Response Example
{
"jsonrpc": "2.0",
"result": [
"0x26aa394eea5630e07c48ae0c9558cef7b6a7c9a35a95a160cb4cad330558dfa56d6f646c755b98a7afd0913860592153322b957be394a0619f20b32679ac1014",
"0x26aa394eea5630e07c48ae0c9558cef70d54f7f0e87470baa5944a45e66a77be5e2ff2b41d89577e728343f47e19f538d684125029b82546b86f1d7dc1c4bd2d"
],
"id": 1
}
Code Examples
JavaScript
async function walkAccounts(pageSize = 256) {
let startKey = null;
const prefix = api.registry.createType('StorageKey', 'System', 'Account').toHex();
while (true) {
const keys = await api.rpc.state.getKeysPaged(prefix, pageSize, startKey);
if (!keys.length) break;
for (const key of keys) {
// process key
}
startKey = keys[keys.length - 1];
}
}
Python
prefix = '0x26aa394eea5630e07c48ae0c9558cef7'
start_key = None
while True:
result = substrate.rpc_request(
method='state_getKeysPaged',
params=[prefix, 128, start_key]
)["result"]
if not result:
break
start_key = result[-1]
Tips
- Keep
count
≤ 1000 to avoid large responses. Increase gradually based on latency and payload size. - For parity with historical calculations, pass the finalized block hash rather than leaving it
null
.