Skip to main content

Contract Discovery

Find deployed contracts and inspect their details with xyz program list and xyz program info.

List Contracts

List all contracts deployed from a specific code ID:
xyz program list <code-id>

Example

xyz program list 1
Output:
Contracts from Code ID 1:

ADDRESS                                           LABEL
xyz1contract1abc123...                            My Token
xyz1contract2def456...                            Test Token
xyz1contract3ghi789...                            Reward Token

Options

FlagDescriptionDefault
--limitMax results10

With Custom Limit

xyz program list 1 --limit 50

Contract Info

Get detailed information about a specific contract:
xyz program info <contract-address>

Example

xyz program info xyz1contract123...
Output:
Contract Information

Address:  xyz1contract123...
Code ID:  1
Label:    My Token
Creator:  xyz1creator...
Admin:    xyz1admin...
Created:  Block 12345

Options

FlagDescription
--hashInclude code hash
--historyShow migration history
--jsonJSON output

With Code Hash

xyz program info xyz1contract... --hash
Output:
Contract Information

Address:   xyz1contract123...
Code ID:   1
Code Hash: abc123def456...
Label:     My Token
Creator:   xyz1creator...
Admin:     xyz1admin...
Created:   Block 12345

With History

xyz program info xyz1contract... --history
Output:
Contract Information

Address:  xyz1contract123...
Code ID:  2
Label:    My Token
Creator:  xyz1creator...
Admin:    xyz1admin...
Created:  Block 12345

Migration History:
  Block 12345: Code 1 → Code 2 (upgrade to v2)
  Block 10000: Initial deployment (Code 1)

JSON Output

xyz program info xyz1contract... --json
{
  "address": "xyz1contract123...",
  "code_id": 1,
  "label": "My Token",
  "creator": "xyz1creator...",
  "admin": "xyz1admin...",
  "created_block": 12345
}

Using xyzd

For more advanced queries:

List All Codes

xyzd query wasm list-code --node tcp://localhost:26657
Output:
code_infos:
- code_id: "1"
  creator: xyz1creator...
  data_hash: ABC123...
  instantiate_permission:
    permission: Everybody
- code_id: "2"
  creator: xyz1creator...
  ...

Contracts by Creator

xyzd query wasm list-contracts-by-creator xyz1creator... --node tcp://localhost:26657

Contract State (Raw)

xyzd query wasm contract-state all xyz1contract... --node tcp://localhost:26657

Discovery Workflow

Find Your Contracts

  1. List all codes you’ve uploaded:
    xyzd query wasm list-code --node tcp://localhost:26657 | grep -A2 "creator: xyz1youraddress"
    
  2. List contracts for each code:
    xyz program list <code-id>
    
  3. Get details on specific contract:
    xyz program info xyz1contract...
    

Find Contracts by Label

# List all CW20 tokens
xyz program list 1 --limit 100 | grep -i "token"

Export Contract List

# Export to JSON
xyz program list 1 --limit 100 | while read addr label; do
  echo "\"$addr\": \"$label\""
done

Contract Properties

Admin

The admin can:
  • Migrate the contract to new code
  • Update the admin
  • Clear the admin (make immutable)
xyz program info xyz1contract... | grep Admin
  • Admin: xyz1admin... - Admin can migrate
  • Admin: None - immutable - No admin, cannot change

Code ID

Identifies the contract code (bytecode):
  • Same code ID = same logic
  • Different instances can have different state
  • Upgrading changes the code ID

Creator

The address that deployed the contract (cannot be changed).

Scripting Examples

List All Your Contracts

#!/bin/bash
MY_ADDRESS="xyz1myaddress..."

# Get all codes
for code_id in $(xyzd query wasm list-code --node tcp://localhost:26657 -o json | jq -r '.code_infos[].code_id'); do
  echo "=== Code ID: $code_id ==="
  xyz program list $code_id --limit 100
done

Monitor Contract Info

#!/bin/bash
CONTRACT="xyz1contract..."

while true; do
  echo "=== $(date) ==="
  xyz program info $CONTRACT
  sleep 60
done

Verify Contract Code

#!/bin/bash
CONTRACT="xyz1contract..."
EXPECTED_HASH="abc123def456..."

ACTUAL_HASH=$(xyz program info $CONTRACT --hash --json | jq -r '.code_hash')

if [ "$ACTUAL_HASH" = "$EXPECTED_HASH" ]; then
  echo "✓ Code hash verified"
else
  echo "✗ Code hash mismatch!"
  echo "  Expected: $EXPECTED_HASH"
  echo "  Actual:   $ACTUAL_HASH"
fi

Troubleshooting

The code ID may have no instances:
# Verify code exists
xyzd query wasm code 1 --node tcp://localhost:26657
Verify the address is correct:
# Address should start with xyz1
# And be the correct length