Skip to main content

Building Contracts

The xyz program build command compiles your Rust contract to optimized WebAssembly (Wasm).

Usage

Run this command from your contract project directory (where Cargo.toml is located).

Build Methods

Docker Build (Default)

Uses the official CosmWasm optimizer for reproducible builds:
Advantages:
  • Reproducible builds (same output every time)
  • Optimized for size
  • Production-ready
Requirements:
  • Docker installed and running

Local Build

Uses your local Rust toolchain:
Advantages:
  • Faster iteration
  • No Docker required
Disadvantages:
  • Larger file size
  • Not reproducible
Requirements:
  • Rust with wasm32-unknown-unknown target:

Options

Output Location

Docker Build

Local Build

Size Comparison

XYZ Chain has a maximum contract size of 800 KB. Both methods typically produce contracts well under this limit.

Build Process

Docker Build Flow

Local Build Flow

Development Workflow

Fast Iteration (Local)

For quick development cycles:

Production (Docker)

For deployments:

Troubleshooting

Install Docker from https://docker.com or use local build:
Run the command from your project root:
Install the Wasm target:
Check your Rust code compiles:
Fix any errors before building for Wasm.
  • Use Docker build (smaller output)
  • Remove unused dependencies
  • Optimize code for size

Verifying Builds

Check File Size

Verify Wasm Format

Check Code Hash

For reproducible builds, verify the hash:

CI/CD Integration

GitHub Actions

Next Steps

After building: