Examples
The fastest way to start a new contract is to clone one of the canonical templates:
otigen new my-contract --from <template-name>
The eight templates otigen new --list exposes are the curated entry points — each one demonstrates a concrete pattern with a working [state] schema, host-fn usage, and (where applicable) a TOML test suite. Beyond the eight, the otigen/examples/ directory carries additional reference contracts that aren't yet promoted to first-class scaffold templates — clone them with git if you want to study them.
Scaffold-able templates
What otigen new --list returns today, with honest status:
| Template | Status | What it demonstrates |
|---|---|---|
counter | ✅ builds, 3/3 tests green | Minimum viable contract — single u64 counter via pyde::declare_storage!{} + #[pyde::entry]. The default otigen new counter --lang rust scaffold, and the starter member otigen init seeds a workspace with. |
erc20-token | ✅ builds, 1/1 test green | ERC20-style fungible token. Typed-arg marshalling: otigen call automatically encodes function arguments per [functions.<fn>].inputs (e.g. address, u128) — see Typed arguments in the command reference. Mapping + composite-key mapping (balances, allowances). |
erc721-token | ✅ builds, 17/17 tests green | ERC721-shape NFT. Per-token ownership, balance_of(owner), single-spender per-token approval cleared atomically on transfer_from. |
upgradeable-proxy | ✅ builds, 16/16 tests green | Upgradeable proxy via delegate_call. Admin-controlled implementation slot with transfer_admin / renounce_admin rotation and namespaced proxy_admin / proxy_logic storage slots. |
dao-governance | ✅ builds, 13/13 tests green | FALCON-signed votes + time phases + hash_blake3-committed execution. The most-composed v1 example. |
simple-multisig | ✅ builds, 14/14 tests green | 3-signer FALCON-512 multisig. Demonstrates falcon_verify + signer-ID lookup + action_digest(target, amount, nonce) view for off-chain signers + nonce-bound replay protection. |
merkle-claim-airdrop | ✅ builds, 17/17 tests green | Merkle-tree airdrop claim. Off-chain commitment + on-chain inclusion verification via hash_blake3. Macro substrate; Vec<u8>-typed proof argument. Ships a #[payable] fn fund() so the contract custodies native PYDE end-to-end and pays out on claim. |
vesting | ✅ builds, 21/21 tests green | Linear vesting with cliff. Time-locked allocation via wave_timestamp. Ships a #[payable] fn fund() so the contract holds native PYDE and releases it to the beneficiary as time accrues. |
Reference contracts in the examples/ tree
These live on disk but aren't (yet) promoted to first-class otigen new templates. Clone them via git if you want to study a specific pattern:
| Reference | Pattern |
|---|---|
hello-rust | Minimal void-void entry + pyde::return without the #[pyde::entry] macro — useful for understanding the macro's expansion. |
counter-rust | Source of the counter scaffold template. Identical surface; included for direct browsing. |
counter-go / counter-as / counter-c | Same counter surface ported to TinyGo / AssemblyScript / C. The starter each otigen new --lang <go|as|c> (or the first member of an otigen init --lang <go|as|c> workspace) scaffolds. |
counter-pair-a + counter-pair-b | Cross-contract calls via pyde::cross_call. Test runner pre-deploys both via [[contracts]] in the test TOML. |
x-call-caller + x-call-target | Typed cross-contract call surface — caller wraps pyde::call::execute_call against a target that exposes a declared [functions.*] surface. |
proxy-logic-v1 + proxy-logic-v2 | Two implementation versions used as delegate targets by upgradeable-proxy end-to-end tests. Useful for understanding the upgrade-path data flow. |
amm-uniswap-v2 | Uniswap-v2-shape constant-product AMM. Pair contract with reserves + LP-share accounting. Largest worked example. |
escrow, multisig-wallet, nft-marketplace, payment-channel | Higher-order patterns. Status varies — read each example's README.md. |
profile-registry | First parachain example. Variable-length-keyed storage exercising the v1-mocked parachain_storage_* host fns. |
borsh-coverage, struct-storage, state-and-emit | Type-coverage + storage-encoding reference contracts. |
*-smoke, *-stress, e2e-soak | Test fixtures consumed by otigen's own CI — not contracts you'd scaffold from. |
This is a curated subset — see the examples/ tree for the full catalog.
To clone one of these into a fresh project:
git clone https://github.com/pyde-net/otigen
cd otigen/examples/<name>
# Read the README, copy the bits you need into your own project tree.
There is no otigen new --from <reference> path for these yet — they aren't in the template registry.
Running an example end-to-end
# Scaffold from a template:
otigen new my-counter --lang rust --from counter # or omit --lang on a TTY and pick it interactively
cd my-counter
# Build + test the local way:
otigen build
otigen test
# Or, against a live devnet:
otigen devnet --rpc-listen 127.0.0.1:9933 & # in another terminal
otigen deploy --from devnet-0 # banner shows BOTH `my-counter` (registered name) and 0x… hex
otigen call my-counter increment --from devnet-0 # by registered name
otigen call my-counter get # view mode — no --from
Verbose test output (with gas, events, traces, storage diffs) is available via:
otigen test -v # + gas used per test
otigen test -vv # + emitted event list (topic0 + sizes)
otigen test -vvv # + per-call traces (fn args / return / gas)
otigen test -vvvv # + storage diffs (slot → before / after)
When to add a new example
The examples/ directory carries the reference contracts; the otigen new --list registry carries the curated subset users land on first. To promote an existing reference to the scaffold registry (or add a wholly new one), the template needs to:
- Demonstrate a host fn or pattern not yet covered by the eight current templates.
- Compile cleanly under the current
HOST_FN_ABI_SPEC§3.5.2 entry shape — use#[pyde::entry]for Rust, not the pre-spec#[no_mangle] pub extern "C". - Ship a
tests/contract.test.tomlthat passesotigen testagainst the live source. - Stay under ~200 lines of contract code unless the pattern genuinely needs more.
When in doubt, counter and erc20-token are the calibration points for "right-sized canonical demo".