state_getStorage
Description#
Retrieves the storage value for a given key. The return value is SCALE-encoded and must be decoded with the appropriate type information from metadata.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
storageKey | string | Yes | Hex-encoded storage key |
blockHash | string | No | Block hash to read historical data |
Returns#
| Field | Type | Description |
|---|---|---|
result | string | null | SCALE-encoded storage value or null if the key is absent |
Request Example#
{
"jsonrpc": "2.0",
"method": "state_getStorage",
"params": [
"0x26aa394eea5630e07c48ae0c9558cef7b6a7c9a35a95a160cb4cad330558dfa56d6f646c755b98a7afd0913860592153322b957be394a0619f20b32679ac1014"
],
"id": 1
}
Response Example#
{
"jsonrpc": "2.0",
"result": "0x0100000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000",
"id": 1
}
Decoding this SCALE blob yields a System.Account record with nonce = 1 and free = 4_000_000_000_000 (0.004 BNC).
Code Examples#
- Python
- JavaScript
account = substrate.query(
module='System',
storage_function='Account',
params=['15mYsj6DpBno58jRoV5HCTiVPFBuWhDLdsWtq3LxwZrfaTEZ']
)
print(account.value['data']['free'])
const storageKey = api.query.system.account.key('15mYsj6DpBno58jRoV5HCTiVPFBuWhDLdsWtq3LxwZrfaTEZ');
const raw = await api.rpc.state.getStorage(storageKey);
const accountInfo = api.createType('FrameSystemAccountInfo', raw);
console.log(accountInfo.data.free.toHuman());
Tips#
- Construct storage keys with helper functions (
api.query.system.account.keyin polkadot.js) to avoid hashing mistakes. - When iterating large sets, use
state_getKeysPagedto collect keys first, then fetch values in batches. - Always decode using runtime metadata corresponding to the block hash you queried.