query_global_state

Casper RPC

How to use it

// yarn add @tatumio/tatum

import { TatumSDK, Casper, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Casper>({ network: Network.CASPER })

const StateRootHash = 'a306a9cf869e52fe9eacdc28aade94215112cc04b6737b3669c35568a47a7dc2'
const Key = 'account-hash-1ed5a1c39bea93c105f2d22c965a84b205b36734a377d05dbb103b6bfaa595a7'
const Path: string[] = []

const result = await tatum.rpc.queryGlobalState({
  state_identifier: { stateRootHash: StateRootHash },
  key: Key,
  path: Path,
})

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/casper-mainnet/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "jsonrpc": "2.0",
    "method": "query_global_state",
    "params": {
        "state_identifier": {
            "StateRootHash": "a306a9cf869e52fe9eacdc28aade94215112cc04b6737b3669c35568a47a7dc2"
        },
        "key": "account-hash-1ed5a1c39bea93c105f2d22c965a84b205b36734a377d05dbb103b6bfaa595a7",
        "path": []
    },
    "id": 4
}'

Overview

query_global_state is an RPC method on the Casper blockchain that allows querying for a value stored under specific keys in the global state using a StateIdentifier.

Parameters

The query_global_state method accepts the following parameters:

  • state_identifier: An object specifying the state identifier.
    • StateRootHash: The state root hash. Example: "a306a9cf869e52fe9eacdc28aade94215112cc04b6737b3669c35568a47a7dc2"
  • key: The key to query. Example: "account-hash-1ed5a1c39bea93c105f2d22c965a84b205b36734a377d05dbb103b6bfaa595a7"
  • path: An array of strings representing the path. Example: []

Return Object

The query_global_state method returns an object with the following fields:

  • api_version: The API version. Example: "1.5.6"
  • stored_value: The stored value at the given key.
  • merkle_proof: The merkle proof for the value.

Response

{
  "jsonrpc": "2.0",
  "id": 4,
  "result": {
    "api_version": "1.5.6",
    "stored_value": {
      "Account": {
        "account_hash": "account-hash-1ed5a1c39bea93c105f2d22c965a84b205b36734a377d05dbb103b6bfaa595a7",
        ...
      }
    },
    "merkle_proof": "010000000e0000000000000000000000000000000000000000000000000000000000000000..."
  }
}

Notes

  • This method returns the value stored under a specific key in the global state at the given state root hash.
  • Ensure to replace the state root hash, key, and path with the actual values you intend to query.

For more detailed information, refer to the official Casper documentation.