Skip to content

Peer-to-peer sync for TypeScript applications

Canvas is a replicated database with an embedded runtime, that lets you write multiplayer TypeScript applications with complex logic and instant sync.

Write your core application logic in a replicated contract, that syncs over libp2p. Users' actions are applied instantly on their machine, and merged seamlessly with others' actions.

Handle conflicts with CRDTs, the data structures that Figma and Linear use to make their UI fast. Or, we also support optimistic rollback, for MMO-style game sync

It's fully open source, and built on SQLite, Postgres, and IndexedDB.

ts
import { useCanvas } from "@canvas-js/hooks"

const contract = {
  models: {
    messages: {
      id: "primary",
      text: "string",
    }
  },
  actions: {
    createMessage: (db, { text }, { address, msgid }) => {
      db.set("messages", { id: msgid, text })
    }
  }
}

const { app } = useCanvas({ topic: "demo.canvas.xyz", contract })   
ts
export const contract = {
  models: {
    messages: {
      id: "primary",
      text: "string"
    }
  },
  actions: {
    createMessage: (db, { text }, { address, txid }) => {
      db.set("messages", { id: txid, text })
    }
  }
}

$ canvas run contract.ts --topic demo.canvas.xyz 

A Peer-to-peer Distributed Runtime

Every Canvas application runs on a distributed log that stores a history of users' actions.

When new applications are started up, they catch up on history using efficient sync to catch up on the latest state.

On top of the sync layer, we've written a peer-to-peer runtime that sandboxes users' actions, that executes them in a deterministic environment to maintain convergence and mergeability.

Replicated log

Now you can develop multiplayer games, local-first applications, and realtime applications with instant responsiveness, while maintaining strong decentralization properties.

For demanding applications, you can shard an application into multiple state containers, and state containers can be snapshotted and compacted as they grow.

To learn more, check out our docs, or join us on Github and Discord.


Components

@canvas-js/okra

A Prolly tree written in Zig, that enables fast peer-to-peer sync for application histories.

@canvas-js/modeldb

A cross-platform relational database wrapper for IDB, SQLite, and Postgres.

Sign in with Ethereum

Log in with an Ethereum wallet. Also supports Cosmos, Solana, and Polkadot.

Sign in with Bluesky

Log in with your decentralized identity from the Bluesky PLC network.

Sign in with OpenID

Log in trustlessly with Google, Apple, or other SSO providers.

© 2024 Canvas Technologies, Inc.