All Products
Search
Document Center

Blockchain as a Service:Query Interface

Last Updated:May 22, 2019

The contract platform provides multiple query operations for you to query blocks, transactions, accounts, and contracts.

Query block headers

You can call the QueryBlockHeader operation to query a specified block header. You can use the block height number or the block hash hash to query the target block header.

Request parameters

One of these two parameters must be used.

Name Required Type Description
block_number false number The height value of the target block.
hash false string The hash of the target block. It is a hexadecimal string prefixed with “0x”.

Example 1

Query a block using the block height.

  1. chain.ctr.QueryBlockHeader({
  2. block_number: 30, // Specify the value of the block height based on your business requirements.
  3. }, (err, data) => {
  4. console.log(data)
  5. })

Example 2

Query a block using the block hash.

  1. chain.ctr.QueryBlockHeader({
  2. hash: '0xe6eebd5b7a6eff8f0af9ac151160e59cc7ec98429822400fc78906c3895bc1aa', // Specify the block hash based on your business requirements.
  3. }, (err, data) => {
  4. console.log(data)
  5. })

Query blocks

QueryLastBlock

You can call this operation to query the last block. This operation does not require any request parameters.

Examples

  1. chain.ctr.QueryLastBlock({}, (err, data) => {
  2. console.log(data)
  3. })

QueryBlock

You can call this operation to query a specified block header. You can use the block height number or the block hash hash to query the target block header.

Request parameters

Name Required Type Description
block_number false number The height value of the target block.
hash false string The hash of the target block. It is a hexadecimal string prefixed with “0x”.
One of these two parameters must be used.

Example 1

Query a block using the block height.

  1. chain.ctr.QueryBlock({
  2. block_number: 30, // Specify the value of the block height based on your business requirements
  3. }, (err, data) => {
  4. console.log(data)
  5. })

Example 2

Query a block using the block hash.

  1. chain.ctr.QueryBlock({
  2. hash: '0xe6eebd5b7a6eff8f0af9ac151160e59cc7ec98429822400fc78906c3895bc1aa', // Specify the block hash based on your business requirements
  3. }, (err, data) => {
  4. console.log(data)
  5. })

Query transactions

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

Request parameters

Name Required Type Description
hash true string The hash of the target transaction. It is a hexadecimal string prefixed with “0x”.

Examples

  1. chain.ctr.QueryTransaction({
  2. hash: '0xf66621372a13c813fe978c060e11a93c28b75f90d2200b9fa700f21433a96a77' //Specify the value based on your business requirements
  3. }, (err, data) => {
  4. console.log('QueryTransaction:', data)
  5. })

Query receipts

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

Request parameters

Name Required Type Description
hash true string The hash value of the target transaction. It is a hexadecimal string prefixed with “0x”.

Examples

  1. chain.ctr.QueryTransactionReceipt({
  2. hash: '0xf66621372a13c813fe978c060e11a93c28b75f90d2200b9fa700f21433a96a77' //Specify the value based on your business requirements
  3. }, (err, data) => {
  4. console.log('QueryTransactionReceipt:', data)
  5. })

Query accounts

You can call the QueryAccount operation to query a specified account. The name of the account is required. The hash value of thename is the identity of the target account. You can also directly provide a hexadecimal string prefixed with “0x” as the identity of the target account.

Request parameters

Name Required Type Description
from true string The name of the target account (not prefixed with “0x”) or the identity of the target account represented by a hexadecimal string prefixed with “0x”. The system calculates the accountname, and the hash of the account name is the identity of the account.

Example 1

Use the account name.

  1. chain.ctr.QueryAccount({
  2. from: 'Tester001'
  3. }, (err, data) => {
  4. console.log('QueryAccount:', data)
  5. })

Example 2

Use the identity of the target account. The identity is represented by a hexadecimal string.

  1. chain.ctr.QueryAccount({
  2. from: '0xc60a9d48105950a0cca07a4c6320b98c303ad42d694a634529e8e1a0a16fcdb5'
  3. }, (err, data) => {
  4. console.log('QueryAccount:', data)
  5. })

Query contract accounts

You can call the QueryContract operation to query a specified contract account. The name of the target contract is required. The hash value of the name is the identity of the target contract. You can also directly provide a hexadecimal string prefixed with “0x” as the identity of the target contract.

Request parameters

The following parameters are encapsulated and passed in as an object.

Name Required Type Description
from true string The name of the target contract (not prefixed with “0x”) or the identity of the target contract represented by a hexadecimal string prefixed with “0x”. If the account name is used, the hash value of the account name is the identity of the contract.

Examples

  1. contractName = 'contract'+Date.now()
  2. let myContract = chain.ctr.contract(contractName, abi)
  3. myContract.new(bytecode, {
  4. from: 'Tester001'
  5. }, (err, contract, data) => {
  6. console.log('contract deploy result:', data)
  7. // Query the deployed contract
  8. chain.ctr.QueryContract({
  9. from: contractName
  10. }, (err, data) => {
  11. console.log('QueryContract:', data)
  12. })
  13. })