Query block headers
queryBlockHeaderByHash
You can call this operation to query a block header using the block header hash.
- Function
public MychainBaseResult<ReplyBlockHeader> queryBlockHeaderByHash(String hash)
Parameters and descriptions:
Name | Required | Type | Description |
---|---|---|---|
hash | true | String | The block hash. |
- Examples
//get hash
String hash = result.getData().getBlock().getBlockHeader().getHash();
//query blockHeader by hash
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
public MychainBaseResult<ReplyBlockHeader> queryBlockHeaderByNumber(long blockNumber)
Parameters and descriptions:
Name | Required | Type | Description |
---|---|---|---|
blockNumber | true | long | The block number. |
- Examples
//query last block
MychainBaseResult<ReplyLastBlock> result = sdk.getQueryService().queryLastBlock();
long blockNumber = result.getData().getBlock().getBlockHeader().getNumber().longValue();
//query blockHeader by Number
MychainBaseResult<ReplyBlockHeader> replyBlockHeader = sdk.getQueryService().queryBlockHeaderByNumber(blockNumber);
queryLastBlockHeader
You can call this operation to query the last block header.
- Function
public MychainBaseResult<ReplyLastBlockHeader> queryLastBlockHeader()
- Examples
MychainBaseResult<ReplyLastBlockHeader> result = sdk.getQueryService().queryLastBlockHeader();
Query blocks
queryBlockByHash
You can call this operation to query a block using the block hash.
- Function
public MychainBaseResult<ReplyBlock> queryBlockByHash(String hash)
Parameters and descriptions:
Name | Required | Type | Description |
---|---|---|---|
hash | true | String | The block hash. |
- Examples
// get hash
String hash = result.getData().getBlock().getBlockHeader().getHash();
// query block by hash
MychainBaseResult<ReplyBlock> replyBlock = sdk.getQueryService().queryBlockByHash(hash);
queryBlockByNumber
You can call this operation to query a block using the block number.
- Function
public MychainBaseResult<ReplyBlock> queryBlockByNumber(long blockNumber)
Parameters and descriptions:
Name | Required | Type | Description |
---|---|---|---|
blockNumber | true | long | The number of the block. |
- Examples
// get block number
long blockNumber = result.getData().getBlock().getBlockHeader().getNumber().longValue();
//query block By Number
MychainBaseResult<ReplyBlock> ReplyBlock = sdk.getQueryService().queryBlockByNumber(blockNumber);
queryLastBlock
You can call this operation to query the last block.
- Function
public MychainBaseResult<ReplyLastBlock> queryLastBlock()
- Examples
MychainBaseResult<ReplyLastBlock> result = sdk.getQueryService().queryLastBlock();
Query transactions
queryTransaction
You can call this operation to query a transaction using the transaction hash.
- Function
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
String hash = replyReceipt.getTxHash();
MychainBaseResult<ReplyTransaction> result = sdk.getQueryService().queryTransaction(hash);
Query receipts
queryTransactionReceipt
You can call this operation to query a receipt using the transaction hash.
- Function
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
String hash = replyReceipt.getTxHash();
MychainBaseResult<ReplyTransactionReceipt> result = sdk.getQueryService().queryTransactionReceipt(hash);
Query accounts
queryAccount
You can call this operation to query an account using the account ID.
- Function
public MychainBaseResult<ReplyAccount> queryAccount(String acctId)
Parameters and descriptions:
Name | Required | Type | Description |
---|---|---|---|
acctId | true | String | The ID of the account. |
- Examples
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
public MychainBaseResult<ReplyContract> queryContract(String acctId)
Parameters and descriptions:
Name | Required | Type | Description |
---|---|---|---|
acctId | true | String | The ID of the account. |
- Examples:
MychainBaseResult<ReplyContract> result = sdk.getQueryService().queryContract(acctId);