For AI agents: an LLM-friendly Markdown version of every page is available by appending .md to its URL or by sending an Accept: text/markdown request header. The full documentation index is at https://www.ankr.com/docs/llms.txt
Skip to main content

Midnight — childstate, rpc, chain, state (2/2)

API reference for Midnight. All methods ->

Part 2 of 2: 1 · 2

state_getKeysPaged

Returns paged storage keys.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Key prefix (hex-encoded) to filter returned keys. Use 0x to retrieve all keys.
    2. <number>: Count — maximum number of keys to return.
    3. <string>: Start key (hex-encoded) to start returning keys from. Use 0x or omit to start from the beginning.
    4. <string> (hex-encoded, 32-byte; optional): Block hash at which to query the keys. If omitted, defaults to the latest block.

Returns

  • <array<string>>: A list of hex-encoded keys in the state that match the specified prefix, limited by the given count and starting from start key.
  • []: Returned if no keys match the given criteria.
  • null: Returned if the provided block hash is invalid or unavailable.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getKeysPaged",
"params": [
"0x",
10,
"0x"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": [
"0x0b20199ace3564d0964e2c4d4a9ba4694e7b9012096b41c4eb3aaf947f6ea429",
"0x0cfd083eaa944b95833ee029c0bdffe34e7b9012096b41c4eb3aaf947f6ea429",
"0x0cfd083eaa944b95833ee029c0bdffe388dcde934c658227ee1dfafcd6e16903",
"0x0cfd083eaa944b95833ee029c0bdffe3e0cdd062e6eaf24295ad4ccfc41d4609",
"0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac",
"0x26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850",
"0x26aa394eea5630e07c48ae0c9558cef734abf5cb34d6244378cddbf18e849d96",
"0x26aa394eea5630e07c48ae0c9558cef74e7b9012096b41c4eb3aaf947f6ea429",
"0x26aa394eea5630e07c48ae0c9558cef75684a022a34dd8bfa2baaf44f172b710",
"0x26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"
]
}

state_getKeysPagedAt

Returns paged keys at a specific block.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Key prefix (hex-encoded) to filter returned keys. Use 0x to retrieve all keys.
    2. <number>: Count — maximum number of keys to return.
    3. <string>: Start key (hex-encoded) to start returning keys from. Use 0x or omit to start from the beginning.
    4. <string> (hex-encoded, 32-byte): Block hash at which to query the keys.

Returns

  • <array<string>>: A list of hex-encoded keys in the state that match the specified prefix, limited by the given count, starting from start key, at the specified block hash.
  • []: Returned if no keys match the given criteria.
  • null: Returned if the provided block hash is invalid or unavailable.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getKeysPagedAt",
"params": [
"0x1a2b3c", // key prefix
10, // maximum number of keys
"0x", // start key (empty = start from first key)
"0x498b4b3aa63dc3abaebf559be8e903357c07589532eb931f9097d533c99800a2" // block hash
]
}'

Response example

{
"jsonrpc": "2.0",
"id": 1,
"result": [
"0x1a2b3c4d5e6f0011",
"0x1a2b3c4d5e6f0022",
"0x1a2b3c4d5e6f0033"
]
}

state_getMetadata

Returns the current runtime metadata.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    • <string> (hex-encoded, 32-byte; optional; default = latest block): Block hash at which to query the metadata.

Returns

  • <string>:

    • Hex-encoded SCALE-encoded metadata for the runtime at the given block hash (or latest block if no hash is provided).
    • This metadata describes the runtime's modules, storage items, extrinsics, and constants.
  • null: Returned if the metadata is unavailable or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getMetadata",
"params": []
}'

Response example

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x6d6574610e8103000c1c73705f636f72651863727970746f2c4163636f756e7449643332000004000401205b75383b2033325d0000040000032000000008000800000503000c08306672616d655f73797374656d2c4163636f756e74496e666f08144e6f6e636501102c4163636f756e74446174610114001401146e6f6e63651001144e6f6e6365000124636f6e73756d657273100120526566436f756e7400012470726f766964657273100120526566436f756e7400012c73756666696369656e7473100120526566436f756e740001106461746114012c4163636f756e74446174610000100000050500140c3c70616c6c65745f62616c616e6365731474797065732c4163636f7..."
}

state_getReadProof

Returns a proof of inclusion for storage entries.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <array<string>>: Keys — an array of hex-encoded state keys to create a read proof for.
    2. <string> (hex-encoded, 32-byte): Block hash at which to generate the proof.

Returns

  • <object>: The read proof object for the requested state keys.
    • at (string): Block hash at which the proof was generated.
    • proof (array<string>): An array of hex-encoded proof nodes required to prove the existence of the keys at the specified block.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getReadProof",
"params": [
[
"0x1a2b3c4d5e6f0011",
"0x1a2b3c4d5e6f0022"
],
"0x94f03b64f26069f6995de0e68442a3470801fd6cdb3a0cf7491ed7ca217f23ec"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": {
"at": "0x94f03b64f26069f6995de0e68442a3470801fd6cdb3a0cf7491ed7ca217f23ec",
"proof": [
"0x802db9803d16513e9985407f820a80efdce62468bf83d4bd901439f1bd90301ed67b140c802558978862c74093fbfbda43640e35d7835a94faef9cc901d7a587db0ddd785180db91f4799a4b8ee3625aa624fdd488505a164f72c123ebb190b131c8259abd36809b8be6ee23eadd747a7fd1201db80a1b3639abf057a79e74ea893c40a4aeefbf80482fbb43c1300417b5e77c5f80ee53cbd3e403c638e893a077bab16a423771818077baa6c5755310b557a6c78028494f837157f8f782f12094d1ff4763d98f05238000e4849ead44a8fe73e1a5536de4173f3c980af6598cb2c9d182eb5be81538ad80f9301ba37a1430856c624d3e305a0a09b900845ddf916cb024988b10b077b55780c5834099227798c65ed9f0771bcb2599e1c4b66e7817e058eb1d6b6f1337ba67"
]
}
}

state_getRuntimeVersion

Returns the runtime version at the current best block.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    • <string> (hex-encoded, 32-byte; optional; default = latest block): Block hash at which to query the runtime version.

Returns

  • <object>: The runtime version information for the given block (or the latest block if none is provided).
    • specName (string): Name of the runtime specification.
    • implName (string): Name of the runtime implementation.
    • authoringVersion (number): Authoring version of the runtime.
    • specVersion (number): Runtime specification version.
    • implVersion (number): Runtime implementation version.
    • apis (array<[string, number]>): List of supported runtime API names and their versions.
    • transactionVersion (number): Transaction format version.
    • stateVersion (number, optional): State format version (if present).

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getRuntimeVersion",
"params": []
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": {
"specName": "midnight",
"implName": "midnight",
"authoringVersion": 1,
"specVersion": 12000,
"implVersion": 0,
"apis": [
[
"0xfbc577b9d747efd6",
1
],
[
"0xdf6acb689907609b",
5
],
[
"0x7d699da8a672e867",
4
]
],
"transactionVersion": 2,
"stateVersion": 1
}
}

state_getStorage

Returns storage value for a given key.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Storage key (hex-encoded) identifying the desired value in the state.
    2. <string> (hex-encoded, 32-byte; optional; default = latest block): Block hash at which to query storage.

Returns

  • <string|null>:
    • The hex-encoded SCALE-encoded value stored under the specified storage key at the given block hash (or at the latest block if no hash is provided).
    • null if the key does not exist or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getStorage",
"params": [
"0x1a2b3c4d5e6f"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": null
}

state_getStorageAt

Returns storage value at a given block.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Storage key (hex-encoded) identifying the desired value in the state.
    2. <string> (hex-encoded, 32-byte): Block hash at which to query storage.

Returns

  • <string|null>:
    • The hex-encoded SCALE-encoded value stored under the specified storage key at the given block hash.
    • null if the key does not exist or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getStorageAt",
"params": [
"0x1a2b3c4d5e6f",
"0x94f03b64f26069f6995de0e68442a3470801fd6cdb3a0cf7491ed7ca217f23ec"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": null
}

state_getStorageHash

Returns hash of the storage entry.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Storage key (hex-encoded) identifying the desired value in the state.
    2. <string> (hex-encoded, 32-byte; optional; default = latest block): Block hash at which to query the storage hash.

Returns

  • <string|null>:
    • The hash (hex-encoded) of the value stored under the specified storage key at the given block hash (or latest block if omitted).
    • null if the key does not exist or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getStorageHash",
"params": [
"0x1a2b3c4d5e6f"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": null
}

state_getStorageHashAt

Returns hash of storage at a specific block.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Storage key (hex-encoded) identifying the desired value in the state.
    2. <string> (hex-encoded, 32-byte): Block hash at which to query the storage hash.

Returns

  • <string|null>:
    • The hash (hex-encoded) of the value stored under the specified storage key at the given block hash.
    • null if the key does not exist or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getStorageHashAt",
"params": [
"0x1a2b3c4d5e6f",
"0x94f03b64f26069f6995de0e68442a3470801fd6cdb3a0cf7491ed7ca217f23ec"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": null
}

state_getStorageSize

Returns byte size of storage for a key.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Storage key (hex-encoded) identifying the desired value in the state.
    2. <string> (hex-encoded, 32-byte; optional; default = latest block): Block hash at which to query the storage size.

Returns

  • <number|null>:
    • The size of the value stored under the specified storage key, in bytes, at the given block hash (or at the latest block if no hash is provided).
    • null if the key does not exist or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getStorageSize",
"params": [
"0x1a2b3c4d5e6f"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": null
}

state_getStorageSizeAt

Returns size of storage at a given block.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <string>: Storage key (hex-encoded) identifying the desired value in the state.
    2. <string> (hex-encoded, 32-byte): Block hash at which to query the storage size.

Returns

  • <number|null>:
    • The size of the value stored under the specified storage key, in bytes, at the given block hash.
    • null if the key does not exist or the block hash is invalid.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_getStorageSizeAt",
"params": [
"0x01020304abcdef",
"0x111122223333444455556666777788889999aaaabbbbccccddddeeeeffff0000"
]
}'

Response example

{
"jsonrpc": "2.0",
"id": 1,
"result": 32
}

state_queryStorageAt

Queries storage at a specific block.

Parameters

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (array; required):

    1. <array<string>>: Keys — an array of hex-encoded storage keys to query.
    2. <string> (hex-encoded, 32-byte; optional; default = latest block): Block hash at which to query.

Returns

  • <array<object>>: An array containing one or more change sets for the specified keys at the given block (or latest block if none is specified).
    • block (string): The block hash at which the values were queried.
    • changes (array<[string, string|null]>): Key-value pairs for each requested storage key:
      • key (string): Hex-encoded storage key.
      • value (string|null): Hex-encoded value stored at that key, or null if no value is set.

Request example

curl -X POST https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "state_queryStorageAt",
"params": [
[
"0x26aa394eea5630e07c48ae0c9558cef7",
"0x1a2b3c4d"
],
"0x84e03f95bf0241e0e6768d510bd5d53fd86353cec4e5903524161e04da3905fc"
]
}'

Response example

{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"block": "0x84e03f95bf0241e0e6768d510bd5d53fd86353cec4e5903524161e04da3905fc",
"changes": [
[
"0x26aa394eea5630e07c48ae0c9558cef7",
null
],
[
"0x1a2b3c4d",
null
]
]
}
]
}