All Products
Search
Document Center

Query interface

Last Updated: May 08, 2020

Query for block headers

queryBlockHeader

This API is used to query for block headers by block hash.

  • Function prototype
  1. public QueryBlockHeaderResponse queryBlockHeader(Hash hash)

The following table describes the basic parameter for a block header query.

Parameter Required Type Description
hash true Hash The block hash.
  • Example
  1. QueryBlockHeaderResponse replyBlockHeader = sdk.getQueryService().queryBlockHeader(hash);

queryBlockHeaderByNumber

This API is used to query for block headers by block number.

  • Function prototype
  1. public QueryBlockHeaderResponse queryBlockHeaderByNumber(BigInteger blockNumber)

The following table describes the basic parameter for a block header query.

Parameter Required Type Description
blockNumber true BigInteger The block number.
  • Example
  1. QueryBlockHeaderResponse replyBlockHeader = sdk.getQueryService().queryBlockHeaderByNumber(blockNumber);

queryLastBlockHeader

This API is used to query for the last block header.

  • Function prototype
  1. public QueryLastBlockHeaderResponse queryLastBlockHeader()
  • Example
  1. QueryLastBlockHeaderResponse result = sdk.getQueryService().queryLastBlockHeader();

Query for blocks

queryBlock

This API is used to query for blocks by block hash.

  • Function prototype
  1. public QueryBlockResponse queryBlock(Hash hash)

The following table describes the basic parameter for a block query.

Parameter Required Type Description
hash true Hash The block hash.
  • Example
  1. QueryBlockResponse replyBlock = sdk.getQueryService().queryBlock(hash);

queryBlockByNumber

This API is used to query for blocks by block number.

  • Function prototype
  1. public QueryBlockResponse queryBlockByNumber(BigInteger blockNumber)

The following table describes the basic parameter for a block query.

Parameter Required Type Description
blockNumber true BigInteger The block number.
  • Example
  1. QueryBlockResponse replyBlock = sdk.getQueryService().queryBlockByNumber(blockNumber);

queryLastBlock

This API is used to query for the last block.

  • Function prototype
  1. public QueryLastBlockResponse queryLastBlock()
  • Example
  1. QueryLastBlockResponse result = sdk.getQueryService().queryLastBlock();

Query for transactions

queryTransaction is used to query for transactions by transaction hash.

  • Function prototype
  1. public QueryTransactionResponse queryTransaction(Hash hash)
  2. public QueryTransactionResponse queryTransaction(Hash hash, BaseFixedSizeByteArray.Fixed20ByteArray groupId)

The following table describes the basic parameters for a transaction query by transaction hash.

Parameter Required Type Description
hash true String The transaction hash.
groupId false Fixed20ByteArray The group where the transactions are queried.
  • Example
  1. QueryTransactionResponse result = sdk.getQueryService().queryTransaction(hash);

Query for receipts

queryTransactionReceipt is used to query for receipts by transaction hash.

  • Function prototype
  1. public QueryTransactionReceiptResponse queryTransactionReceipt(Hash hash)
  2. public QueryTransactionReceiptResponse queryTransactionReceipt(Hash hash, BaseFixedSizeByteArray.Fixed20ByteArray groupId)

The following table describes the basic parameters for a receipt query by transaction hash.

Parameter Required Type Description
hash true String The transaction hash.
groupId false Fixed20ByteArray The group where the receipts are queried.
  • Example
  1. QueryTransactionReceiptResponse result = sdk.getQueryService().queryTransactionReceipt(hash);

Query for accounts

queryAccount is used to query for accounts by account ID.

  • Function prototype
  1. public QueryAccountResponse queryAccount(Identity acctId)

The following table describes the basic parameter for an account query by account ID.

Parameter Required Type Description
acctId true Identity The account ID.
  • Example
  1. QueryAccountResponse result = sdk.getQueryService().queryAccount(acctId);

Query for contracts

queryContract is used to query for contracts by contract account.

  • Function prototype
  1. public QueryContractResponse queryContract(Identity acctId)

The following table describes the basic parameter for a contract query by contract account.

Parameter Required Type Description
acctId true Identity The account ID.
  • Example
  1. QueryContractResponse result = sdk.getQueryService().queryContract(acctId);

Query a block for transaction receipts

queryBlockTxReceipts is used to query a block for transaction receipts by block height.

  • Function prototype
  1. public QueryBlockTxReceiptsResponse queryBlockTxReceipts(BigInteger blockNumber);

The following table describes the basic parameter for querying a block for transaction receipts by block height.

Parameter Required Type Description
blockNumber true BigInteger The block height.
  • Example
  1. QueryContractResponse result = sdk.getQueryService().queryContract(BigIntger.valueOf(1L);