state_getKeys - JSON-RPC Method
Description
Returns a list of storage keys that share a given prefix. This method is helpful when you need to discover child keys beneath a map, such as iterating through all system accounts or fuel tank records in Enjin Matrix.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
prefix | string | Yes | Hex-encoded storage prefix (typically twox128(module) + hasher(storage) ) |
blockHash | string | null | No | Block hash for historical queries; null uses the best block |
Returns
An array of hex-encoded storage keys matching the supplied prefix.
Request Example
{
"jsonrpc": "2.0",
"method": "state_getKeys",
"params": [
"0x26aa394eea5630e07c48ae0c9558cef7",
null
],
"id": 1
}
Response Example (truncated)
{
"jsonrpc": "2.0",
"result": [
"0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac",
"0x26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850",
"0x26aa394eea5630e07c48ae0c9558cef734abf5cb34d6244378cddbf18e849d96",
"…"
],
"id": 1
}
Code Examples
cURL
curl https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "state_getKeys",
"params": ["0x26aa394eea5630e07c48ae0c9558cef7", null],
"id": 1
}'
JavaScript
const prefix = '0x26aa394eea5630e07c48ae0c9558cef7'; // Module: System
const body = {
jsonrpc: '2.0',
method: 'state_getKeys',
params: [prefix, null],
id: 1
};
const keys = await fetch('https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
}).then((r) => r.json());
console.log(keys.result.length);
Python
import json
import requests
prefix = "0x26aa394eea5630e07c48ae0c9558cef7" # twox128("System")
response = requests.post(
"https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY",
headers={"Content-Type": "application/json"},
data=json.dumps({
"jsonrpc": "2.0",
"method": "state_getKeys",
"params": [prefix, None],
"id": 1,
}),
timeout=10,
)
keys = response.json()["result"]
print(f"Returned {len(keys)} keys")
Tips
- Use
state_getKeysPaged
for large datasets; it adds pagination controls to avoid heavy responses. - Combine with
state_getStorage
to fetch the associated values for each discovered key. - Remember that map storage keys append hashes and encoded keys (e.g.,
Blake2_128Concat(AccountId)
), so you may need to post-process the suffix.