Skip to content

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 + Supabase, but the protocol does not care what language or stack you use.

The invariant contract

Read PROTOCOL.md first. It defines:

  • The six document types (Promise, Pocket, Account, Record, Tx, Signature)
  • RFC 8785 canonical JSON (cross-runtime parity is load-bearing)
  • ed25519 signatures over SHA-256 hashes
  • The JSON-RPC envelope and replay protection
  • The client-orchestrated settlement cascade (lead → follow)
  • The state machine (approved → held → confirmed → settled)
  • 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

LayerReference choiceYour choice
LanguageTypeScriptRust, Go, Python, Zig, whatever
RuntimeDeno (Edge Functions)Node, Bun, Rust Axum, Go net/http, Python FastAPI
DatabasePostgresSQLite, CockroachDB, DynamoDB, custom WAL
ClientCLIWeb UI, mobile app, Telegram bot, AI agent loop
Key storagePlaintext JSONEncrypted keystore, hardware wallet, OS keychain
Inbox10s pollingWebSocket, SSE, push, email
HostingSupabaseVPS, Fly, Cloudflare, home server

See IMPLEMENTATION.md for how the reference team made each choice and what alternatives you might consider.

Quickstart checklist

If you’re building a bank from scratch:

  1. Implement RFC 8785 canonical JSON. Verify cross-runtime parity.
  2. Implement ed25519 sign/verify and SHA-256. Use audited libraries.
  3. Define the six doc types and their validators.
  4. Build the JSON-RPC envelope handler with replay protection.
  5. Implement propose_leg, hold_leg, confirm_receipt, settle_leg, reject_leg.
  6. Enforce sum-to-zero on every settle.
  7. Enforce at most one active hold per account.
  8. Expose GET /.well-known/barter-bank.json.
  9. Write a client that can orchestrate a trade end-to-end (bilateral or N-party).
  10. Run it against the reference banks to verify interop.

The protocol library

The reference packages/protocol/ is MIT-licensed and dependency-light. It runs under Bun, Deno, and browser. You can import it directly or treat it as the spec to port:

FileWhat to port
canonical.tsRFC 8785 canonicalizer. Must be byte-identical.
crypto.tsed25519 + SHA-256 + base58. Thin wrappers; easy to replicate.
schemas.tsDoc validators. Replicate in your type system of choice.
invite.tsbarter:// string encode/decode.
deal.tsDeal-graph builder: given transfers, compute Tx, roles, predecessors.

Read more