Documentation / Start / Quick start
Quick start
This page takes an app from nothing to a decision that 3 members of a community sign on their own computers.
1Install the package
Your app gets protocol0 from npm like any other package.
npm install protocol0The package goes on npm when the first version is published.
2Start a community
Ann starts Flood Relief Network on her computer and names Bob and Cat as the other first members.
import { ready, newKeyPair, publicOf, Copy } from 'protocol0'
await ready()
const bob = newKeyPair()
const cat = newKeyPair()
const relief = Copy.start({
key: newKeyPair(),
me: { name: 'Ann' },
name: 'Flood Relief Network',
founders: [
{ name: 'Bob', key: publicOf(bob) },
{ name: 'Cat', key: publicOf(cat) },
],
pages: [{ id: 'fund', name: 'Relief fund', content: 'The fund holds $90,000.' }],
})3Propose a change
Ann proposes to send $40,000 to Hill End and that changes the Relief fund page. Her proposal counts as her signature so it starts at 1 of 3.
const code = relief.propose({
title: 'Send $40,000 to Hill End',
change: { type: 'page', page: 'fund', content: 'The fund holds $50,000.' },
})4Send it to the other copies
Ann's computer sends the new entries to the relay. Bob and Cat collect them when their computers come online.
import { HttpRelay, sync } from 'protocol0'
await sync(relief, [new HttpRelay('https://relay.protocol0.org')])5Watch the decision
Bob signs on his own copy and that makes 2 of 3 signatures so the change counts and every copy shows the new page.
import { syncDirect } from 'protocol0'
const bobsCopy = Copy.load({ key: bob, items: relief.items() })
bobsCopy.sign(code)
syncDirect(relief, bobsCopy)
console.log(relief.view().proposals[0].status)decidedThe program prints decided because 2 of 3 members have signed.
In this example both copies run on 1 computer. In real use Bob's copy runs on his own computer and gets the entries through the relay.
Something wrong on this page