state_getKeys
Enumerate storage keys for a given prefix on Astar. Useful for auditing map entries.
Description
Returns storage keys with a given prefix. Because Astar staking maps can be large, use this method sparingly and follow with state_getKeysPaged for controlled pagination.
Parameters
| Position | Type | Description |
|---|---|---|
| 0 | string | Storage key prefix in hex |
| 1 (optional) | string | Block hash |
| 2 (optional) | number | Result limit (ignored on some node versions) |
Request Example
Get collator session keys by prefixing Session.NextKeys (no account parameter).
{
"jsonrpc": "2.0",
"method": "state_getKeys",
"params": [
"0xcec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb3",
null,
5
],
"id": 7
}Response Example
{
"jsonrpc": "2.0",
"id": 7,
"result": [
"0xcec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb30165c612f75544f29a2b2224d8a6944df8f70196c856ae141ecf1aeb3de10d54461317f2fdeae21b",
"0xcec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb302a1a4c9e333badf063b6446a3e6b0781d73ea137f9c74f59918312cb7938a1f234287ea08418633",
"…"
]
}If a node returns Response is too big, switch to state_getKeysPaged with smaller page sizes.
Code Examples
substrate = SubstrateInterface(url="wss://api-astar.n.dwellir.com/YOUR_API_KEY", ss58_format=5)
prefix = substrate.generate_storage_hash('Session', 'NextKeys')
keys = substrate.rpc_request('state_getKeys', [prefix, None, 5])['result']
print(keys[:3])state_call
Call a runtime API function on Astar. Execute on-chain computations like account nonce lookups, fee estimation, and custom runtime logic without submitting a transaction.
state_getKeysPaged
Enumerate storage keys with pagination on Astar. Iterate over storage maps like accounts, validators, and assets efficiently with cursor-based pagination.