Documentation / Build / Start a community
Start a community
A community starts with 1 call that writes the first entry of its record. This page shows what that call takes and how to read the result.
These pages say community for 1 group of members and rule 9 uses community for several groups that share 1 record.
1Make the keys
Call ready() once so that protocol0 can load its sealing library. Then make 1 key pair for each founder with newKeyPair().
A key pair is made on the computer of its owner and never leaves it. In real use each founder makes their own and the example makes all 3 on 1 computer to stay short.
import { ready, newKeyPair, publicOf, needed, Copy } from 'protocol0'
await ready()
const ann = newKeyPair()
const bob = newKeyPair()
const cat = newKeyPair()2Start the community
Ann calls Copy.start with her key, her name, the name of the community, the other founders and the pages they begin with.
A founder is named by a public key that publicOf takes from a key pair. Every founder is an ordinary member from the first entry on.
const relief = Copy.start({
key: ann,
me: { name: 'Ann' },
name: 'Flood Relief Network',
founders: [
{ name: 'Bob', key: publicOf(bob) },
{ name: 'Cat', key: publicOf(cat) },
],
subchats: [{ id: 'general', name: 'General' }],
pages: [{ id: 'fund', name: 'Relief fund', content: 'The fund holds $90,000.' }],
})3Read what you started
view() returns what the record says now and needed tells how many signatures a body of 3 members needs under a number of the constitution.
protocol0 adds the Constitution and the Rule book as 2 pages of its own before the pages you name. By default every number is more than half of the members.
const view = relief.view()
const signatures = needed(view.settings.rulePage, view.members.length)
console.log(view.name + ' has ' + view.members.length + ' members')
console.log('Pages: ' + view.pages.map((p) => p.name).join(', '))
console.log('A change needs ' + signatures + ' signatures')
console.log('Sub chats: ' + view.subchats.map((s) => s.name).join(', '))Flood Relief Network has 3 members
Pages: Constitution, Rule book, Relief fund
A change needs 2 signatures
Sub chats: GeneralThe program prints the name of the community with its 3 members, the 3 pages, the 2 signatures that a change needs and the sub chat.
4Choose more
Copy.start takes a few more choices and each one has a default so a community that leaves them out still works.
constitutionTextandrulesTexthold the words of the Constitution and the Rule book.settingschanges the numbers of the constitution and a number can ask for more than half and never for less.subchatsnames the sub chats where members talk andpagesnames the pages that the community keeps.teamsmakes teams from the first entry on as the Teams inside a community page shows.groupsmakes a community of several groups instead of 1 group.metacarries data of your app that protocol0 keeps and never reads.
Next
Something wrong on this page