Skip to main content

Contract Hub Tutorial

Push and pull Modality contracts through the Rust hub (modal hub start) or a chain remote (decentralized). A JavaScript hub remains under services/contract-hub when a JS-hosted API is needed.

Hub vs Chain

FeatureHubChain
URL formathttp://.../ip4/.../p2p/...
ValidationServer-side (modality-lang)Consensus
SpeedFastDepends on network
TrustHub operatorValidators

Quick Start

1. Start the Hub

modal hub start --host 127.0.0.1 --port 8080 --rpc-port 0 --data-dir .hub

The current modal hub command group starts the server only. See Hub Commands.

2. Create a contract (optional)

curl -s -X POST http://127.0.0.1:8080/contracts \
-H 'content-type: application/json' \
-d '{"template":"escrow"}'

modal c push will also create the remote contract id if it does not exist.

Push/Pull Workflow

modal c remote add origin http://127.0.0.1:8080/contracts/my-contract
modal c push origin
modal c pull origin

Credentials in .modal-hub/credentials.json are optional on the Rust hub. They are used by the JavaScript hub in services/contract-hub. The Rust hub accepts unauthenticated push/pull on localhost.

Multi-Party Collaboration

Alice publishes

modal c remote add origin http://127.0.0.1:8080/contracts/escrow-with-bob
modal c push origin

Bob clones and contributes

modal c clone http://127.0.0.1:8080/contracts/escrow-with-bob
modal c set-named-id /parties/bob.id ./bob.passfile
modal c commit --all --sign bob.passfile -m "Bob joins"
modal c push origin

Chain Sync (Decentralized)

For trustless operation, sync to the chain instead:

modal c remote add chain /ip4/validator.modality.network/tcp/4001/p2p/12D3KooW...
modal c push chain

Chain commits are validated by consensus — no single party can censor or tamper.

See also