Smart Contracts
XYZ Chain supports CosmWasm smart contracts - Rust-based programs that run on the blockchain, similar to Solana programs.Why CosmWasm?
Rust Safety
Memory-safe language prevents common vulnerabilities
Familiar to Solana Devs
Rust-based like Solana programs
Rich Ecosystem
CW20, CW721, and many more standards
IBC Compatible
Cross-chain contracts via IBC
Contract Lifecycle
- Scaffold - Create project structure with
xyz init - Build - Compile Rust to optimized Wasm with
xyz program build - Deploy - Upload and instantiate with
xyz program deploy - Interact - Execute methods and query state
Commands
| Command | Description |
|---|---|
xyz init | Scaffold new contract project |
xyz program build | Compile to optimized Wasm |
xyz program deploy | Upload and instantiate contract |
xyz program execute | Call contract method |
xyz program query | Read contract state |
xyz program list | List deployed contracts |
xyz program info | Contract details |
xyz localnet | Local development network |
Quick Start
1. Start Local Network
2. Scaffold Project
3. Build Contract
4. Deploy
5. Interact
Project Structure
xyz init creates:
Key Files
| File | Purpose |
|---|---|
lib.rs | Exports contract entry points |
contract.rs | instantiate, execute, query functions |
msg.rs | InstantiateMsg, ExecuteMsg, QueryMsg |
state.rs | Storage using cw-storage-plus |
error.rs | Custom error types |
Contract Entry Points
Every CosmWasm contract has three entry points:Message Types
InstantiateMsg
Configuration when creating the contract:ExecuteMsg
Actions that modify state:QueryMsg
Read-only requests:Gas & Fees
CosmWasm operations use more gas than standard transactions:| Operation | Typical Gas |
|---|---|
| Store (upload) | 1,000,000 - 5,000,000 |
| Instantiate | 200,000 - 500,000 |
| Execute | 100,000 - 300,000 |
| Query | Free (no tx) |
Development Workflow
Standards
Common contract standards available:| Standard | Description | Use Case |
|---|---|---|
| CW20 | Fungible tokens | Token creation |
| CW721 | Non-fungible tokens | NFTs |
| CW1 | Proxy contracts | Upgradability |
| CW3 | Multisig | DAOs, shared wallets |
| CW4 | Groups | Membership management |