cosmwasm development

QoreChain supports CosmWasm smart contracts, enabling developers to write secure, sandboxed programs in Rust that compile to WebAssembly. CosmWasm contracts run alongside EVM and SVM programs within the QoreChain triple-VM architecture.


Prerequisites

Dependency
Version
Purpose

Rust

Latest stable

Contract compilation

wasm32-unknown-unknown

target

WebAssembly compilation target

cargo-generate

Latest

Project scaffolding

cosmwasm-std

1.5+

CosmWasm standard library

Install the Wasm target:

rustup target add wasm32-unknown-unknown

Contract Lifecycle

CosmWasm contracts follow a five-step lifecycle: Build, Store, Instantiate, Execute, and Query.

1

Build

Compile your contract to optimized WebAssembly:

cd my-contract

# Standard build
cargo build --release --target wasm32-unknown-unknown

# Optimized build (recommended for deployment)
docker run --rm -v "$(pwd)":/code \
  cosmwasm/rust-optimizer:0.15.0

The optimized .wasm file will be in the artifacts/ directory.

2

Store

Upload the compiled contract to the chain:

qorechaind tx wasm store contract.wasm \
  --from mykey \
  --gas auto \
  --gas-adjustment 1.3 \
  -y

After the transaction confirms, query the stored code ID:

qorechaind query wasm list-code
3

Instantiate

Create a new contract instance from a stored code ID:

qorechaind tx wasm instantiate <code-id> \
  '{"count": 0, "owner": "qor1..."}' \
  --label "my-counter-contract" \
  --from mykey \
  --no-admin \
  --gas auto \
  --gas-adjustment 1.3 \
  -y
Flag
Description

<code-id>

Numeric ID returned from the store transaction

--label

Human-readable label for this instance

--no-admin

No admin address (contract is immutable)

--admin <address>

Set an admin who can migrate the contract

Retrieve the contract address:

qorechaind query wasm list-contracts-by-code <code-id>
4

Execute

Call a contract's execute entry point to change state:

qorechaind tx wasm execute <contract-addr> \
  '{"increment": {}}' \
  --from mykey \
  --gas auto \
  -y

Execute with funds attached:

qorechaind tx wasm execute <contract-addr> \
  '{"deposit": {}}' \
  --amount 1000000uqor \
  --from mykey \
  -y
5

Query

Read contract state without submitting a transaction:

qorechaind query wasm contract-state smart <contract-addr> \
  '{"get_count": {}}'

Query responses are returned as JSON.


Useful Queries

# List all stored code
qorechaind query wasm list-code

# List all instances of a specific code ID
qorechaind query wasm list-contracts-by-code <code-id>

# Get contract info (code ID, admin, label)
qorechaind query wasm contract <contract-addr>

# Get raw contract state by key
qorechaind query wasm contract-state raw <contract-addr> <key-hex>

# Get full contract state (all keys)
qorechaind query wasm contract-state all <contract-addr>

# Get contract history (instantiate/migrate events)
qorechaind query wasm contract-history <contract-addr>

Contract Structure

A typical CosmWasm contract has three entry points:


Cross-VM Calls

CosmWasm contracts can interact with contracts deployed on the EVM and SVM through the x/crossvm module. Cross-VM calls from CosmWasm use the asynchronous message path:

The message is submitted to a queue and processed by the EndBlocker in the next block. See Cross-VM Interoperability for the full message lifecycle.


Module Integration

CosmWasm contracts can interact with QoreChain SDK modules through standard message passing:


Contract Migration

If the contract was instantiated with an --admin address, the admin can migrate it to a new code ID:

This calls the migrate entry point on the new code with the existing contract state.


Next Steps

  • Cross-VM Interoperability -- Call EVM and SVM contracts from CosmWasm

  • SVM Development -- Deploy BPF programs on QoreChain

  • EVM Precompiles -- Access PQC and AI features from Solidity