Skip to main content

How to make queries with parameters

This recipe demonstrates how to perform queries with parameters using the postchain-client against a Chromia blockchain. This is the fundamental pattern for retrieving data from blockchain queries.

Prerequisites

  • Node.js
  • Postchain client: npm install postchain-client

Demo script

Key Features

This recipe includes examples for:

  • Parameterized queries - Using the client.query() method with custom parameters
  • Buffer handling - Working with hex-encoded Buffer parameters for blockchain data
  • Query configuration - Adapting query names and parameters for different blockchains
  • Result handling - Processing and displaying query results

Common Query Examples

This pattern works for various blockchain queries:

  • Account balances - get_balance with account ID parameter
  • Transaction history - Query transactions for specific accounts
  • Asset information - Retrieve details about blockchain assets
  • Custom dapp queries - Any query defined in your dapp's Rell code

Parameter Types

Queries can accept various parameter types:

  • Buffer/Hex data - Account IDs, transaction IDs, asset IDs
  • Strings - Text-based identifiers or search terms
  • Numbers - Amounts, timestamps, pagination limits
  • Objects - Complex structured data for advanced queries

Learn more