Skip to content

docs(examples): add CosmWasm contract examples and end-to-end deploy walkthrough #38

Description

@danbaruka

Summary

Safrochain ships with CosmWasm enabled (see wasmbindings/ and the x/cw-hooks module), but the repository contains no runnable CosmWasm contract examples or a walkthrough that takes a new developer from cargo new to a deployed contract on a local Safrochain node. New builders coming from the broader CosmWasm ecosystem currently have to piece this together themselves.

Goal

Add an examples/cosmwasm/ directory with at least three small, self-contained reference contracts and a step-by-step guide that uses safrochaind to compile, upload, instantiate, and execute them against a local node.

Suggested example contracts

  1. counter/ — the classic Hello-World: Increment, Reset, GetCount. Demonstrates state, messages, queries, and unit testing with cw-multi-test.
  2. cw20-mintable/ — a minimal mintable CW20 token. Demonstrates the standard token interface and how to mint/transfer/query balances.
  3. clock-counter/ — a contract registered with x/clock that auto-increments on every block. Shows how to use Safrochain's custom clock module — this is one of the chain's differentiators and currently has no public example.

Optional bonus:

  1. cw-hooks-listener/ — subscribes to events via x/cw-hooks. Same rationale as above: it's a Safrochain-specific feature with no published example.

Suggested walkthrough (examples/cosmwasm/README.md)

  1. Prerequisites (rustup, wasm32-unknown-unknown target, cargo-generate, safrochaind)
  2. Build with cargo wasm + optional cosmwasm/optimizer Docker image
  3. safrochaind tx wasm store … to upload the bytecode (with gas/fee guidance using usaf)
  4. safrochaind tx wasm instantiate …
  5. safrochaind tx wasm execute … and safrochaind query wasm contract-state smart …
  6. How to register the contract with x/clock or x/cw-hooks where applicable
  7. Troubleshooting (gas estimation, wasm size limit, query vs execute)

Why this matters

  • Lowers the barrier to entry. New CosmWasm developers can clone the repo and have a working contract on a Safrochain devnet in under 30 minutes.
  • Documents Safrochain-specific features. x/clock and x/cw-hooks are real differentiators but invisible to anyone who hasn't read the Go code. Examples are the most credible form of documentation for them.
  • Drives adoption. Most chains compete for contract developers on tooling and examples. A complete examples/ directory is one of the highest-leverage docs investments.
  • Stress-tests the chain. Maintaining runnable examples surfaces breakage from SDK / wasmd / wasmvm bumps before integrators hit it.

Acceptance criteria

  • examples/cosmwasm/<name>/ directory per contract, each independently buildable
  • Each contract has unit tests passing under cargo test
  • Each contract has a Makefile or justfile with build, optimize, store, instantiate, execute targets
  • Top-level examples/cosmwasm/README.md walks through the full local-node flow with copy-pasteable commands
  • Examples reference usaf for fees and safro-testnet-1 as the chain ID, matching the main README

Why this is a good first issue

Each contract can be tackked independently — a newcomer can pick "counter" or "cw20-mintable" without needing deep chain knowledge, and the Rust side is well-trodden territory in the CosmWasm community. Comment to claim one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions