Build an AppChain#
An AppChain is your own chain on TOG: a Wasm runtime written in Rust with the TOG SDK. Hub validators check every block it produces, so it is secured from its first block without validators of its own, and it can order compute jobs from the Grid and exchange messages with other TOG chains without bridges.
What the SDK gives you#
| Part | What |
|---|---|
| Runtime framework | The base for a deterministic Wasm runtime: no floating point, weights for execution time and proof size |
| Standard modules | system, balances, transaction_payment, sudo, cgmp (messages to other chains), compute (jobs on the Grid), assets, collator_selection |
| Template runtime | A working chain to start from |
tog-collator |
The collator and full node: builds blocks, serves JSON-RPC, follows the Hub |
tog |
The developer tool: new workspace, reproducible builds, chain specs, local devnet, tests, benchmarks |
Install#
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Rust 1.88 or newer
rustup target add wasm32-unknown-unknown
cargo install --git <SOURCE_REPO_URL> --tag <RELEASE_TAG> tog-sdk tog-collator-node
This installs tog and tog-collator.
Create a chain#
tog new my-chain
cd my-chain
tog new writes a workspace from the minimal template: the standard modules, sudo and the executive. It pins the SDK to its git repository; pass --sdk-rev <TAG> to pin a release, or --sdk PATH to build against a local checkout.
Templates
--template compute (the minimal chain with the compute API) and --template evm are planned and not in the SDK yet.
Build#
tog build --release
Builds the runtime's Wasm, runs the same pre-check the Hub validators run on uploaded code, and writes the Wasm and its compressed upload to target/tog/. It prints the code hash, which is what the Hub registers.
For a code hash anyone can reproduce from your source, build inside a pinned container image:
tog build --release --image <IMAGE>@sha256:<DIGEST>
Test#
tog test
Runs your chain's tests natively against an in-memory chain with a simulated Hub, simulated other chains and scripted compute results. Arguments after -- go to cargo test.
Run a local devnet#
tog dev
Starts Hub validators on your machine, registers your runtime, starts a collator authoring blocks and funds a development account, until you press Ctrl-C. The collator's JSON-RPC is on port 9944.
| Option | Default | What |
|---|---|---|
--runtime FILE |
built from the workspace | Use this Wasm instead |
--validators N |
4 | Hub validators |
--rpc-port N |
9944 | The collator's JSON-RPC port |
--block-ms N |
2000 | Hub block time |
--workers |
Also start three compute workers and three storage workers, so the chain can request jobs | |
--executor KIND |
mock |
With --workers: mock (default) returns the outputs the image declares without running anything; process runs the image's script locally |
Weights#
tog bench --runtime target/tog/runtime.wasm --out src/weights.rs
Measures the template-shaped runtime's call weights on its Wasm and writes weights.rs. The numbers depend only on the code, not on your machine.
Chain spec#
tog chain-spec --runtime target/tog/runtime.wasm \
--chain-id <CHAIN_ID> --network-id 2 \
--authority <AUTHOR_ACCOUNT> \
--balance <ACCOUNT>=<BASE_UNITS> \
--root <SUDO_ACCOUNT> \
--out spec/
Writes runtime.wasm, genesis.bin and chain-spec.toml, which registration uses. --chain-id must be the id the Hub will assign next (tog-collator status shows it as next_chain_id). The spec also sets the chain's rules for the workers that may run its jobs:
| Option | What |
|---|---|
--min-isolation TIER |
The weakest isolation tier workers may run the chain's jobs in: t0, t1, t2 or t3 (default t0). Workers on the first public testnet offer t1 |
--min-bond N |
Bond workers hold on top of the Hub minimum, in atto-TOG |
--min-reputation N |
Reputation workers must have |
--min-gpus N |
GPUs workers must have |
--module ID |
A verification module: how the chain decides two results are the same; repeatable |
Next: Deploy an AppChain to the testnet.