Querying the Blockchain

hmy provides several subcommands under the blockchain subcommand which let you query the blockchain.

The Harmony blockchain is a sharded blockchain, therefore some commands depend on which shard you target. The shard you target when querying is controlled by the --node flag. For example, if a transaction is made between shard 0 and shard 1, the transaction receipt must be queried from whichever shard sent the funds - in this case shard 0, so the --node flag would look like this:

--node="https://api.s0.t.hmny.io"

For other shards, please replace the s0 with the appropriate shard number - eg. s1 for shard 1, s2 for shard 2 etc.

List of available commands

By using ./hmy blockchain help command we can see that the following options are available:

  • block-by-number - get a harmony blockchain block by block number

  • current-nonce - current nonce of an account delegation information about delegations

  • known-chains - print out the known chain-ids

  • latest-header - get the latest header

  • median-stake - median stake of top 320 validators with delegations applied stake (pre-epos processing)

  • protocol-version - the version of the Harmony Protocol

  • transaction-by-hash - get transaction by hash

  • transaction-receipt - get information about a finalized transaction validator information about validators

  • pool - get transaction pool information

Here are some examples of the above commands that you will use frequently:

transaction-by-hash

Checking the hash of your transaction to see the transaction data and if the transaction has been completed

Using the Binary:

Using the Shell Wrapper:

Example:

transaction-receipt

Get information about a finalized transaction:

Using the Binary:

Using the Shell Wrapper:

Example:

latest-header command

Checking the network status, last block, epoch, leaders, based on the shard number:

Using the Binary:

Using the Shell Wrapper:

Example:

block-by-number

Note the block-number provided must be in hex with a 0x prefix.

For example if you call latest-header and get a result of 10657 you convert this to hex which is 29A1 and then use the value 0x29A1 for block-number. This can be done using

printf '0x%x\n' 10617 #0X29a1

Using the Binary:

Using the Shell Wrapper:

Example:

Last updated

Was this helpful?