For Developers
Build your own implementation
The barter.game protocol is intentionally small. You can read the full contract in an afternoon. The reference implementation is TypeScript + Deno Deploy, but the protocol does not care what language or stack you use.
The invariant contract
Read the protocol/ spec first. It defines:
- The document types: Voucher, Account, Order, Mandate, Record, Offer, Signature, Subscription, Address — Records are bank-minted and identified by ULID
- RFC 8785 canonical JSON (cross-runtime parity is load-bearing)
- ed25519 signatures over SHA-256 hashes
- The JSON-RPC envelope and replay protection
- Coordinator-orchestrated approval: each holder signs their own Order (
lead/follow), a coordinator creates the records and clears each Order with a signed Mandate, and the banks self-advance with a lead-first settle cascade - The state machine (created → approved → held → settled / rejected)
- The concurrency invariants (sum-to-zero, one active hold per account)
Everything in that file is the contract. Change it and you are no longer speaking barter.game v1.
What you CAN change
| Layer | Reference choice | Your choice |
|---|---|---|
| Language | TypeScript | Rust, Go, Python, Zig, whatever |
| Runtime | Deno (Deno Deploy) | Node, Bun, Rust Axum, Go net/http, Python FastAPI |
| Database | Deno KV | SQLite, Postgres, CockroachDB, DynamoDB, custom WAL |
| Client | Web UI (browser SPA, apps/web) | CLI, mobile app, Telegram bot, AI agent loop |
| Key storage | Plaintext JSON | Encrypted keystore, hardware wallet, OS keychain |
| Inbox | 10s polling | WebSocket, SSE, push, email |
| Hosting | Deno Deploy | VPS, Fly, Cloudflare, home server |
See the reference implementation notes for how the reference team made each choice and what alternatives you might consider.
Quickstart checklist
If you’re building a bank from scratch:
- Implement RFC 8785 canonical JSON. Verify cross-runtime parity.
- Implement ed25519 sign/verify and SHA-256. Use audited libraries.
- Define the doc types and their validators.
- Build the JSON-RPC envelope handler with replay protection.
- Implement
submit_docs,create_records,submit_mandate,subscribe,notify_signatures,get_record_signatures, and the read methods (get_voucher,get_balance,list_accounts,list_account_records,list_offers, …). - Implement the advance engine: records self-advance created → approved → held → settled, evaluated on every incoming signature.
- Enforce sum-to-zero on every settle.
- Enforce at most one active hold per account.
- Expose
GET /<name>/barter-bank.json(andGET /<name>/address/<pubkey>if you want an address directory). - Write a client that can run a trade end-to-end (publish Orders → discover Offers → create records → mandate → banks settle), bilateral or N-party.
- Run it against the reference banks to verify interop.
The protocol library
The reference packages/protocol/ is MIT-licensed, dependency-light, and a single source file — src/index.ts. It runs under Bun, Deno, and browser. You can import it directly or treat it as the spec to port:
Piece (all in src/index.ts) | What to port |
|---|---|
| Canonicalizer | RFC 8785 canonical JSON. Must be byte-identical. |
| Crypto | ed25519 + SHA-256 + base58. Thin wrappers; easy to replicate. |
| Doc types + validators | Voucher, Account, Order, Mandate, Record, Offer, Signature, Subscription, Address. Replicate in your type system of choice. |