BlockX Documentation
  • Introduction
    • BlockX
    • Tokens
    • Transactions
    • Inflation
    • Keys
      • Keyring
      • Multisig
    • Gas Fees
    • Wallet and Accounts
      • Adding BlockX to Metamask
      • Adding BlockX to Keplr
      • Transfers Between Wallets
      • Backup
    • Deploying Smart Contracts
      • Remix
      • Hardhat
  • BlockX White Paper
  • The BCX Token
  • Governance
    • Proposals
      • Proposal Tips
      • Submit a Proposal
    • Community Pool
    • Chain Parameters
  • Technical Concepts
    • Architecture
    • Accounts
    • Chain ID
    • Encoding
    • Pending State
  • dApp Developers
    • Establishing Connections
    • BlockX Clients
    • Guides
      • Wallet Integration
      • Smart Contract Incentive Registration
      • Tracing Transactions
      • Query Balances
    • Localnet
      • Single-node
      • Multi-node
    • Testnet
      • Testnet Commands
    • Ethereum JSON-RPC
      • JSON-RPC Server
      • Running the Server
      • Namespaces
      • JSON-RPC Methods
      • Events
    • Tendermint RPC
  • Protocol Developers
    • Modules
      • auth
        • Concepts
        • State
        • AnteHandlers
        • Keepers
        • Vesting
        • Parameters
        • Client Auth
      • bank
        • State
        • Keepers
        • Messages
        • Events
        • Parameters
        • Client
      • crisis
        • State
        • Messages
        • Events
        • Parameters
        • Client
      • distribution
        • Concepts
        • State
        • Begin Block
        • Messages
        • Hooks
        • Events
        • Parameters
        • Client
      • epochs
        • Concepts
        • State
        • Events
        • Keepers
        • Hooks
        • Queries
        • Future Improvements
      • erc20
        • Concepts
        • State
        • State Transitions
        • Transactions
        • Hooks
        • Events
        • Parameters
        • Clients
      • evidence
        • Concepts
        • State
        • Messages
        • Events
        • Parameters
        • BeginBlock
        • Client
      • evm
        • Concepts
        • State
        • State Transitions
        • Transactions
        • ABCI
        • Hooks
        • Events
        • Parameters
        • Client
      • feemarket
        • Concepts
        • State
        • Begin block
        • End block
        • AnteHandlers
        • Keeper
        • Events
        • Client
        • Future Improvements
        • Parameters
      • feesplit
        • Concepts
        • State
        • State Transitions
        • Transactions
        • Hooks
        • Events
        • Parameters
        • Clients
        • Future Improvements
      • gov
        • Concepts
        • State
        • Messages
        • Events
        • Future Improvements
        • Parameters
        • Client
      • incentives
        • Concepts
        • State
        • State Transitions
        • Transactions
        • Hooks
        • Events
        • Parameters
        • Clients
      • ibc-core
      • inflation
        • Concepts
        • State
        • Hooks
        • Events
        • Parameters
        • Clients
      • slashing
        • Concepts
        • State
        • Messages
        • BeginBlock
        • Hooks
        • Events
        • Staking Tombstone
        • Parameters
        • CLI
      • staking
        • State
        • State Transitions
        • Messages
        • Begin-Block
        • End-Block
        • Hooks
        • Events
        • Parameters
        • Client
      • upgrade
        • Concepts
        • State
        • Events
        • Client
        • Resources
      • vesting
        • Concepts
        • State
        • State Transitions
        • Transactions
        • AnteHandlers
        • Events
        • Clients
    • Module Accounts
    • IBC Channels
    • Ethermint API
  • Validators
    • Quick Start
    • Telemetry
    • Security
      • Tendermint KMS
      • Tendermint KMS + Ledger
      • Validator Security Checklist
      • Validator Backup
    • Snapshots, Archive Nodes
    • FAQ
  • Delegators
    • Staking Process
  • Tokenomics
  • Block Explorers
Powered by GitBook
On this page
  • blockxd & Tendermint RPC
  • JSON-RPC
  • gRPC
  1. dApp Developers
  2. Guides

Query Balances

This guide will cover the following query methods:

  • blockxd & Tendermint RPC

  • JSON-RPC

  • gRPC

blockxd & Tendermint RPC

Upon installation and configuration of the BlockX Daemon, developers can query account balances using blockxd with the following CLI command:

$ blockxd query bank balances $BLOCKXADDRESS --count-total=$COUNTTOTAL --height=$HEIGHT --output=$OUTPUT --node=$NODE
balances:
- amount: "1000000000000000000"
  denom: abcx
- amount: "100000"
  denom: ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518
pagination:
  next_key: null
  total: "0"

where:

  • $BLOCKXADDRESS is the BlockX address with balances of interest (eg. blockx1...).

  • (optional) $COUNTTOTAL counts the total number of records in all balances to query for.

  • (optional) $HEIGHT is the specific height to query state at (can error if node is pruning state).

  • (optional) $OUTPUT is the output format (eg. text).

  • (optional if running local node) $NODE is the Tendermint RPC node information is requested from

Details of non-native currencies (ie. not ablockx) can be queried with the following CLI command:

$ blockxd query erc20 token-pair $DENOM --node=$NODE --height=$HEIGHT --output=$OUTPUT
token_pair:
  contract_owner: OWNER_MODULE
  denom: ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518
  enabled: true
  erc20_address: 0xFA3C22C069B9556A4B2f7EcE1Ee3B467909f4864

where $DENOM is the denomination of the coin (eg. ibc/ED07A3391A1...).

JSON-RPC

# Request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":[`$ETHADDRESS`, `$BLOCK`],"id":1}' -H "Content-Type: application/json" $NODE

# Result
{"jsonrpc":"2.0","id":1,"result":"0x36354d5575577c8000"}

where:

  • $ETHADDRESS is the Etherum hex-address the balance is to be queried from. Note that BlockX addresses

  • (optional if running local node) $NODE is the JSON-RPC node information is requested from

# Request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"from":`SENDERCONTRACTADDRESS`, "to":`ERCCONTRACTADDRESS`, "data":`$DATA`}, `$BLOCK`],"id":1}'  -H "Content-Type: application/json" $NODE

# Result
{"jsonrpc":"2.0","id":1,"result":"0x"}

where:

  • $SENDERCONTRACTADDRESS is the Ethereum hex-address this smart contract call is sent from.

  • $ERCCONTRACTADDRESS is the Ethereum hex-address of the ERC-20 contract corresponding to the coin denomination being queried.

  • (optional if running local node) $NODE is the JSON-RPC node information is requested from

gRPC

# Request
grpcurl $OUTPUT -d '{"address":`$BLOCKXADDRESS`}' $NODE cosmos.bank.v1beta1.Query/AllBalances

# Result
{
  "balances": [
    {
      "denom": "stake",
      "amount": "1000000000"
    }
  ],
  "pagination": {
    "total": "1"
  }
}

where:

  • $BCXADDRESS is the BlockX address with balances of interest (eg. "blockx1...").

  • $NODE is the Cosmos gRPC node information is requested

  • (optional) $OUTPUT is the output format (eg. plaintext).

import (
    "context"
    "fmt"

  "google.golang.org/grpc"

    sdk "github.com/cosmos/cosmos-sdk/types"
  "github.com/cosmos/cosmos-sdk/types/tx"
)

func queryState() error {
    myAddress, err := GetBlockXAddressFromBech32("blockx1...") // blockx address with balances of interest.
    if err != nil {
        return err
    }

    // Create a connection to the gRPC server.
    grpcConn := grpc.Dial(
        "https://grpc.bd.blockxnet.com:9090", // your gRPC server address.
        grpc.WithInsecure(), // the SDK doesn't support any transport security mechanism.
    )
    defer grpcConn.Close()

    // This creates a gRPC client to query the x/bank service.
    bankClient := banktypes.NewQueryClient(grpcConn)
    bankRes, err := bankClient.AllBalances(
        context.Background(),
        &banktypes.QueryAllBalancesRequest{Address: myAddress},
    )
    if err != nil {
        return err
    }

    fmt.Println(bankRes.GetBalances()) // prints the account balances.

    return nil
}
PreviousTracing TransactionsNextLocalnet

Last updated 1 year ago

Developers can query account balances of ablockx using the eth_getBalance JSON-RPC method in conjunction with :

$BLOCK is the block number or block hash (eg. "0x0"). The reasoning for this parameter is due to .

Developers can also query account balances of x/erc20-module registered coins using the eth_call JSON-RPC method in conjunction with :

$DATA is the hash of the method signature and encoded parameters. balanceOf is a required method in every ERC-20 contract, and the encoded parameter is the address which is having its balance queried. For additional information, see the .

$BLOCK is the block number or block hash (eg. "0x0"). The reasoning for this parameter is due to .

Developers can use with the AllBalances endpoint to query account balance by address for all denominations:

State can also be queried using gRPC within a Go program. The idea is to create a gRPC connection, then use the -generated client code to query the gRPC server.

curl
EIP-1898
curl
balanceof
Ethereum Contract ABI
EIP-1898
grpcurl
Protobuf