How to Use Blockchain Query APIs

·

Blockchain-as-a-Service (BaaS) platforms empower developers and enterprises to interact with blockchain networks efficiently. One of the core capabilities is accessing on-chain data through well-defined blockchain query APIs. This guide walks you through the essential methods for querying transaction receipts, transactions, block headers, accounts, and smart contracts—providing clear examples and practical usage patterns.

Whether you're auditing transactions, verifying smart contract execution, or building blockchain explorers, mastering these API endpoints is crucial. Below, we detail each method with its parameters, return structure, and sample requests and responses.


Core API Overview

All query operations follow a consistent pattern:

Each request must include authentication and identification parameters:

👉 Unlock powerful blockchain insights with advanced tools and real-time data access.


Read Transaction Receipt

Use this method to retrieve the detailed outcome of a specific transaction.

Method Name

QUERYRECEIPT

Function

Fetch the receipt of a specified transaction using its hash.

Request Parameters

ParameterRequiredTypeDescription
methodYesstringSet to QUERYRECEIPT
accessIdYesstringTenant AK ID
tokenYesstringAccess token
bizidYesstringBlockchain ID
hashYesstringTransaction hash
requestStrNostringDecryption key for encrypted logs/results

Response Parameters

ParameterTypeDescription
successbooleanRequest success status
codestringError code (e.g., "200" for success)
datastringOn success: JSON string of receipt; on failure: error message

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYRECEIPT",
  "hash": "cd3b5e4db44d121024a645c93b27ba3e49ca87d6dcc94ffb35e96faf1c1840a8",
  "token": "d211cb86-c155-4e11-b073-f406a27b7619"
}

Response Example

{
  "code": "200",
  "data": "{\"blockNumber\":4868192,\"gasUsed\":20110,\"logs\":[...],\"output\":\"\",\"result\":0}",
  "success": true
}
Note: The data field contains a JSON string. Parse it to access structured receipt details such as logs, gas usage, and execution result.

Read Transaction Data

Retrieve the raw content of a transaction.

Method Name

QUERYTRANSACTION

Function

Get the full details of a specific transaction by its hash.

Request Parameters

ParameterRequiredTypeDescription
methodYesstringSet to QUERYTRANSACTION
accessIdYesstringTenant AK ID
tokenYesstringAccess token
bizidYesstringBlockchain ID
hashYesstringTransaction hash
requestStrNostringOptional decryption key

Response Parameters

Same as QUERYRECEIPT.

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "hash": "cd3b5e4db44d121024a645c93b27ba3e49ca87d6dcc94ffb35e96faf1c1840a8",
  "method": "QUERYTRANSACTION",
  "token": "951610a3-1058-4487-acd0-97756ec67e2c"
}

Response Example

{
  "code": "200",
  "data": "{\"blockNumber\":4868192,\"transactionDO\":{\"data\":\"aGVsbG8gd29ybGQ=\",\"timestamp\":1592397562669}}",
  "success": true
}
Note: The data.transactionDO.data field is Base64-encoded. Decode it (e.g., using Base64.decodeBase64) to retrieve plaintext payload.

Read Block Header

Fetch metadata of a specific block.

Method Name

QUERYBLOCK

Function

Get header information (metadata) of a specified block.

Request Parameters

ParameterRequiredTypeDescription
methodYesstringSet to QUERYBLOCK
accessIdYesstringTenant AK ID
tokenYesstringAccess token
bizidYesstringBlockchain ID
requestStrYesstringBlock number

Response Parameters

Same as above.

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYBLOCK",
  "requestStr": "100",
  "token": "6e13e618-a9f4-4dc4-8fab-cf9698351fc7"
}

Response Example

{
  "code": "200",
  "data": "{\"block\":{\"blockHeader\":{\"number\":100,...}}}",
  "success": true
}

Read Latest Block Header

Quickly access the most recent block.

Method Name

QUERYLASTBLOCK

Function

Retrieve header of the latest mined block.

Request Parameters

Same as QUERYBLOCK, but no requestStr needed.

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYLASTBLOCK",
  "token": "9445dfbf-51a5-406e-8561-6c4b2aed9802"
}

Read Block Body

Retrieve full content of a block, including transactions.

Method Name

QUERYBLOCKBODY

Function

Get complete block data including transaction list and receipts.

Request Parameters

Same as QUERYBLOCK.

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYBLOCKBODY",
  "requestStr": "100",
  "token": "56780675-b52a-43b4-a52d-e134e12dec97"
}

Query Raw Block Header List

Fetch multiple block headers based on conditions.

Method Name

QUERYBLOCKHEADERINFOSRAW

Function

Retrieve raw header data for a range of blocks.

Request Parameters

ParameterRequiredTypeDescription
requestStrYesstringJSON-formatted query: block number, max amount, sort order

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYBLOCKHEADERINFOSRAW",
  "requestStr": "{\"blockNumber\":\"100\",\"maxAmount\":\"3\",\"reverse\":\"1\"}",
  "token": "b7117bab-088f-4455-936d-352e6d3092ca"
}

Query Blockchain Account

Inspect account state on the chain.

Method Name

QUERYACCOUNT

Function

Retrieve balance, status, and metadata of a blockchain account.

Request Parameters

ParameterRequiredTypeDescription
requestStrYesstringJSON with queryAccount field containing account ID

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYACCOUNT",
  "requestStr": "{\"queryAccount\":\"ff89d3d4569342028b4767e779e55994\"}",
  "token": "4d7c9e42-ff8f-4f38-8fe7-a4efbdba72ec"
}

Query Smart Contract Information

Access deployed contract details.

Method Name

QUERYCONTRACT

Function

Retrieve metadata and code info of a smart contract.

Request Parameters

ParameterRequiredTypeDescription
contractNameYesstringName of the contract

Request Example

{
  "accessId": "baas_admin",
  "bizid": "12eba21a66ed4d2795b833ce7ebd750c",
  "method": "QUERYCONTRACT",
  "contractName": "wasm_test_contract_with_log",
  "token": "4d7c9e42-ff8f-4f38-8fe7-a4efbdba72ec"
}

👉 Discover how real-time blockchain analytics can enhance your development workflow.


Frequently Asked Questions (FAQ)

Q: What authentication is required for these APIs?
A: You need an accessId, token, and bizid for every request. These identify your tenant and authorize access to the blockchain instance.

Q: How do I decode Base64-encoded transaction data?
A: Use standard Base64 decoding. In Java: new String(Base64.getDecoder().decode("aGVsbG8gd29ybGQ=")).

Q: Can I query historical blocks by timestamp?
A: Not directly. You must first determine the block number corresponding to a timestamp using external indexing tools or event logs.

Q: What does a successful response look like?
A: A response with "success": true, "code": "200", and valid JSON in the data field.

Q: Are there rate limits on these APIs?
A: Yes, consult your BaaS provider’s documentation for specific throttling policies to avoid service interruption.

Q: How can I verify contract execution results?
A: Use QUERYRECEIPT with the transaction hash. Check the result and logs fields in the decoded response.


Core Keywords

blockchain query API, BaaS platform, transaction receipt, smart contract query, block header retrieval, blockchain data access, API integration, on-chain data verification