⚠️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

Returns all storage keys that match a given prefix. This is useful when you need to discover dynamic child keys, such as zkSBT registries or user credential entries.

Parameters

ParameterTypeRequiredDescription
keyPrefixstringYesHex-encoded storage key prefix (usually the module/storage hash preimage).
atstringNoOptional block hash to query historical state.

Returns

FieldTypeDescription
resultarrayHex-encoded full storage keys that match the prefix.

Request Example

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

Response:

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

Generate Prefixes with @polkadot/api

import { ApiPromise, WsProvider } from '@polkadot/api';

const provider = new WsProvider('wss://api-manta-atlantic-mainnet.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });

// Example: derive prefix for zkSBT schemas storage
const prefix = api.query.zksbt.schemas.keyPrefix();
const keys = await api.rpc.state.getKeys(prefix.toHex());

console.log('Found', keys.length, 'schema keys');

Usage Notes

  • state_getKeys can be expensive on large prefixes; prefer state_getKeysPaged for pagination.
  • The prefix must already include any hashing strategy (e.g., Twox128 + Twox64Concat). Use the metadata helpers from @polkadot/api to avoid manual hashing.
  • Combine with state_getStorage to fetch the values behind discovered keys.