Query storage¶
In Substrate, any pallet can introduce new storage items that will become part of the blockchain state. These storage items can be simple single values, or more complex storage maps.
The runtime exposes several storage functions to query those storage items and are provided in the metadata. See the metadata documentation for more information of available storage functions for several Substrate runtimes.
Example¶
1 2 3 4 |
|
State at a specific block hash¶
1 2 3 4 5 6 7 8 9 |
|
Type decomposition information¶
Some storage functions need parameters and some of those parameter types can be quite complex to compose.
To retrieve more information how to format those storage function parameters, the helper function get_param_info()
is available:
1 2 3 4 5 6 7 8 9 10 11 |
|
Querying multiple storage entries at once¶
When a large amount of storage entries is requested, the most efficient way is to use the query_multi()
function.
This will batch all the requested storage entries in one RPC request.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Query a mapped storage function¶
Mapped storage functions can be iterated over all key/value pairs, for these type of storage functions query_map()
can be used.
The result is a QueryMapResult
object, which is an iterator:
1 2 3 4 5 |
|
These results are transparently retrieved in batches capped by the page_size
kwarg, currently the
maximum page_size
restricted by the RPC node is 1000
1 2 3 4 5 |
|
Querying a DoubleMap
storage function:
1 2 3 4 5 |
|