⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

state_getKeys

Description

Returns all storage keys with a given prefix. Use this to discover accounts, vToken positions, or other on-chain items before fetching values with state_getStorage.

Parameters

ParameterTypeRequiredDescription
prefixstringYesHex-encoded storage key prefix
blockHashstringNoBlock hash for historical queries

Returns

Array of matching hex-encoded storage keys.

Request Example

{
"jsonrpc": "2.0",
"method": "state_getKeys",
"params": [
"0x26aa394eea5630e07c48ae0c9558cef7",
null
],
"id": 1
}

Response Example

{
"jsonrpc": "2.0",
"result": [
"0x26aa394eea5630e07c48ae0c9558cef7b6a7c9a35a95a160cb4cad330558dfa56d6f646c755b98a7afd0913860592153322b957be394a0619f20b32679ac1014",
"0x26aa394eea5630e07c48ae0c9558cef7c8e63e63a001c280f6dc809625f6ce9c53c51e645dd0a2c3e0800a9c53aac6ffe81912f6526f364eb8e4a36c2e304931"
],
"id": 1
}

Code Examples

JavaScript

const keyPrefix = api.registry.createType('StorageKey', 'System', 'Account').toHex();
const keys = await api.rpc.state.getKeys(keyPrefix, null);
console.log('Found', keys.length, 'System.Account entries');

Python

keys = substrate.rpc_request(
method='state_getKeys',
params=['0x26aa394eea5630e07c48ae0c9558cef7', None]
)["result"]
print(len(keys))

Tips

  • For large datasets prefer state_getKeysPaged to avoid stress-testing nodes.
  • Combine with Bifrost-specific prefixes (e.g., Omnipool or Farming) to iterate liquidity pools and reward schedules.