Skip to main content

Querying Contracts

The xyz program query command reads contract state without submitting a transaction. Queries are free and instant.

Usage

Arguments

Basic Query

Output:

Options

Query Formats

Inline JSON

With Parameters

From File

Output Formats

Pretty (Default)

Raw (Compact)

Use --raw for piping to other tools:

Common Query Patterns

Single Value

Address Parameter

Paginated List

With Start After

CW20 Token Queries

Token Info

Balance

Minter

All Accounts

Scripting

Extract Value

Monitor State

Conditional Logic

Query vs Execute

Error Handling

Contract Not Found

Invalid Query Message

Check your contract’s QueryMsg enum for valid query names.

Query Error from Contract

The contract returned an error (e.g., querying non-existent item).

Troubleshooting

Check your contract’s QueryMsg:
Note: Rust GetCount becomes JSON get_count (snake_case).
Validate your query:
The contract may return empty for non-existent data. Check if the item exists first.