query_balance

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 blockHash = '13c2d7a68ecdd4b74bf4393c88915c836c863fc4bf11d7f2bd930a1bbccacdcb'
const purseIdentifier = 'account-hash-0909090909090909090909090909090909090909090909090909090909090909'

const result = await tatum.rpc.queryBalance({
  state_identifier: {
    name: 'BlockHash',
    value: { blockHash: blockHash },
  },
  purse_identifier: {
    name: 'main_purse_under_account_hash',
    value: { mainurse_under_account_hash: purseIdentifier },
  },
})

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 '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "query_balance",
  "params": [
      {
        "name": "state_identifier",
        "value": {
          "BlockHash": "13c2d7a68ecdd4b74bf4393c88915c836c863fc4bf11d7f2bd930a1bbccacdcb"
        }
    },
      {
        "name": "purse_identifier",
        "value": {
          "main_purse_under_account_hash": "account-hash-0909090909090909090909090909090909090909090909090909090909090909"
        }
      }
    ]
}'

Overview

query_balance is an RPC method on the Casper blockchain that retrieves the balance of a purse using a PurseIdentifier and StateIdentifier. This method allows you to query for the balance of a specific purse at a given block hash.

Parameters

The query_balance method accepts the following parameters:

  • state_identifier: An object specifying the state identifier, which includes:
    • BlockHash: The hash of the block to query. Example: "13c2d7a68ecdd4b74bf4393c88915c836c863fc4bf11d7f2bd930a1bbccacdcb"
  • purse_identifier: An object specifying the purse identifier, which includes:
    • main_purse_under_account_hash: The account hash of the main purse. Example: "account-hash-0909090909090909090909090909090909090909090909090909090909090909"

Return Object

The query_balance method returns an object with the following fields:

  • api_version: The API version. Example: "1.5.6"
  • balance: The balance represented in motes. Example: "1000000000000000000000000000000000"

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "api_version": "1.5.6",
    "balance": "1000000000000000000000000000000000"
  }
}

Notes

  • This method returns the balance of a specific purse at the given block hash.
  • Ensure to replace the block hash and purse identifier with the actual values you intend to query.

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