Docs

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

PositionTypeDescription
0stringStorage key prefix in hex
1 (optional)stringBlock hash
2 (optional)numberResult limit (ignored on some node versions)

Request Example

Get collator session keys by prefixing Session.NextKeys (no account parameter).

JSON
{
  "jsonrpc": "2.0",
  "method": "state_getKeys",
  "params": [
    "0xcec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb3",
    null,
    5
  ],
  "id": 7
}

Response Example

JSON
{
  "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

Python
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])