All Products
Search
Document Center

Blockchain as a Service:Query Interface

Last Updated:May 21, 2019

Query block headers

queryBlockHeaderByHash

You can call this operation to query a block header using the block header hash.

  • Function
  1. public MychainBaseResult<ReplyBlockHeader> queryBlockHeaderByHash(String hash)

Parameters and descriptions:

Name Required Type Description
hash true String The block hash.
  • Examples
  1. //get hash
  2. String hash = result.getData().getBlock().getBlockHeader().getHash();
  3. //query blockHeader by hash
  4. MychainBaseResult<ReplyBlockHeader> replyBlockHeader = sdk.getQueryService().queryBlockHeaderByHash(hash);

queryBlockHeaderByNumber

You can call this operation to query the header of a block using the block number.

  • Function
  1. public MychainBaseResult<ReplyBlockHeader> queryBlockHeaderByNumber(long blockNumber)

Parameters and descriptions:

Name Required Type Description
blockNumber true long The block number.
  • Examples
  1. //query last block
  2. MychainBaseResult<ReplyLastBlock> result = sdk.getQueryService().queryLastBlock();
  3. long blockNumber = result.getData().getBlock().getBlockHeader().getNumber().longValue();
  4. //query blockHeader by Number
  5. MychainBaseResult<ReplyBlockHeader> replyBlockHeader = sdk.getQueryService().queryBlockHeaderByNumber(blockNumber);

queryLastBlockHeader

You can call this operation to query the last block header.

  • Function
  1. public MychainBaseResult<ReplyLastBlockHeader> queryLastBlockHeader()
  • Examples
  1. MychainBaseResult<ReplyLastBlockHeader> result = sdk.getQueryService().queryLastBlockHeader();

Query blocks

queryBlockByHash

You can call this operation to query a block using the block hash.

  • Function
  1. public MychainBaseResult<ReplyBlock> queryBlockByHash(String hash)

Parameters and descriptions:

Name Required Type Description
hash true String The block hash.
  • Examples
  1. // get hash
  2. String hash = result.getData().getBlock().getBlockHeader().getHash();
  3. // query block by hash
  4. MychainBaseResult<ReplyBlock> replyBlock = sdk.getQueryService().queryBlockByHash(hash);

queryBlockByNumber

You can call this operation to query a block using the block number.

  • Function
  1. public MychainBaseResult<ReplyBlock> queryBlockByNumber(long blockNumber)

Parameters and descriptions:

Name Required Type Description
blockNumber true long The number of the block.
  • Examples
  1. // get block number
  2. long blockNumber = result.getData().getBlock().getBlockHeader().getNumber().longValue();
  3. //query block By Number
  4. MychainBaseResult<ReplyBlock> ReplyBlock = sdk.getQueryService().queryBlockByNumber(blockNumber);

queryLastBlock

You can call this operation to query the last block.

  • Function
  1. public MychainBaseResult<ReplyLastBlock> queryLastBlock()
  • Examples
  1. MychainBaseResult<ReplyLastBlock> result = sdk.getQueryService().queryLastBlock();

Query transactions

queryTransaction

You can call this operation to query a transaction using the transaction hash.

  • Function
  1. public MychainBaseResult<ReplyTransaction> queryTransaction(String hash)

Parameters and descriptions:

Name Required Type Description
hash true String The transaction hash.
groupId false Fixed20ByteArray Queries a transaction in a specified group.
  • Examples
  1. String hash = replyReceipt.getTxHash();
  2. MychainBaseResult<ReplyTransaction> result = sdk.getQueryService().queryTransaction(hash);

Query receipts

queryTransactionReceipt

You can call this operation to query a receipt using the transaction hash.

  • Function
  1. public MychainBaseResult<ReplyTransactionReceipt> queryTransactionReceipt(String hash)

Parameters and descriptions:

Name Required Type Description
hash true String The transaction hash.
groupId false Fixed20ByteArray Queries a receipt in a specified group.
  • Examples
  1. String hash = replyReceipt.getTxHash();
  2. MychainBaseResult<ReplyTransactionReceipt> result = sdk.getQueryService().queryTransactionReceipt(hash);

Query accounts

queryAccount

You can call this operation to query an account using the account ID.

  • Function
  1. public MychainBaseResult<ReplyAccount> queryAccount(String acctId)

Parameters and descriptions:

Name Required Type Description
acctId true String The ID of the account.
  • Examples
  1. MychainBaseResult<ReplyAccount> result = sdk.getQueryService().queryAccount(acctId);

Query contract accounts

queryContract

You can call this operation to query a contract using the contract account.

  • Function
  1. public MychainBaseResult<ReplyContract> queryContract(String acctId)

Parameters and descriptions:

Name Required Type Description
acctId true String The ID of the account.
  • Examples:
  1. MychainBaseResult<ReplyContract> result = sdk.getQueryService().queryContract(acctId);