Skip to main content

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#

ParameterTypeRequiredDescription
storageKeystringYesHex-encoded storage key
blockHashstringNoBlock hash to read historical data

Returns#

FieldTypeDescription
resultstring | nullSCALE-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#

account = substrate.query(
module='System',
storage_function='Account',
params=['15mYsj6DpBno58jRoV5HCTiVPFBuWhDLdsWtq3LxwZrfaTEZ']
)
print(account.value['data']['free'])

Tips#

  • Construct storage keys with helper functions (api.query.system.account.key in polkadot.js) to avoid hashing mistakes.
  • When iterating large sets, use state_getKeysPaged to collect keys first, then fetch values in batches.
  • Always decode using runtime metadata corresponding to the block hash you queried.