How to run queries
Queries are read-only operations that retrieve data from your blockchain without modifying state. This guide shows you how to use queries during development and testing.
Prerequisites
- Chromia CLI installed
- Rell dapp project created with local node running OR access to a deployed dapp
Basic query workflow
Step 1: Verify your node is running
# Check if local node is responding
curl http://localhost:7740
Step 2: Run a simple query
# Test the default hello_world query (--local is the default)
chr query hello_world
Expected output:
"Hello World!"
Note: You can also use the Blockchain RID explicitly:
chr query --blockchain-rid <BlockchainRID> hello_world
Replace <BlockchainRID>
with the actual Blockchain RID from your node output. You can find this in the node startup
output as: Blockchain RID: FC17B67D66F6F35A5D8B75ED3F83AE222FB8C8FCA241624F06285150F10C6BAC
Query methods overview
Local queries (development)
# Default local query
chr query hello_world
# Explicit blockchain RID (equivalent to --local for development)
chr query --blockchain-rid <BlockchainRID> hello_world
Remote queries (deployed dapps)
# Query deployed dapp using network and blockchain name
chr query --network testnet --blockchain my_rell_dapp hello_world
Query parameters
When you create queries that accept parameters, use this syntax based on the official CLI documentation:
Basic parameter types
# String parameters (quoting optional for simple strings)
chr query my_query arg1=Alice arg2=hello
# Strings with spaces (require quotes)
chr query my_query 'arg1="My Neighbor"' arg2=hello
# Integer parameters
chr query my_query arg1=123 arg2=456
# Multiple parameters example from official docs
chr query hello_world foo=17 bar=hello 'baz="hello world"'
Advanced parameter types
# Byte array parameters
chr query my_query 'arg=x"AB12"'
# Using -- to avoid additional quotes
chr query my_query -- arg1=foo arg2=x"AB12"
# Dictionary/map parameters
chr query my_query 'arg=["key": 12]'
# Array parameters
chr query my_query 'arg=[foo, 123]'
Testing against deployed dapps
Testnet queries
# Basic query on deployed dapp
chr query --network testnet --blockchain my_rell_dapp hello_world
# Query with parameters on deployed dapp
chr query --network testnet --blockchain my_rell_dapp my_query foo=17 bar=hello
Next steps
After mastering queries:
- Run operations to modify blockchain state
- Run tests to verify your queries work correctly
- Deploy your dapp to make queries available publicly