OrbitDB

Peer-to-Peer Databases for the Decentralized Web

README

OrbitDB


Matrix CircleCI Status npm version node

OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses IPFS as its data storage and IPFS Pubsub to automatically sync databases with peers. It's an eventually consistent database that uses CRDTs for conflict-free database merges making OrbitDB an excellent choice for decentralized apps (dApps), blockchain applications and local-first web applications.



OrbitDB provides various types of databases for different data models and use cases:

- log: an immutable (append-only) log with traversable history. Useful for "latest N" use cases or as a message queue.
- feed: a mutable log with traversable history. Entries can be added and removed. Useful for "shopping cart" type of use cases, or for example as a feed of blog posts or "tweets".
- keyvalue: a key-value database just like your favourite key-value database.
- docs: a document database to which JSON documents can be stored and indexed by a specified key. Useful for building search indices or version controlling documents and data.
- counter: Useful for counting events separate from log/feed data.

All databases are implemented on top of ipfs-log, an immutable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. If none of the OrbitDB database types match your needs and/or you need case-specific functionality, you can easily implement and use a custom database store of your own.

Project status & support


Status: in active development
Compatible with js-ipfs versions <= 0.52 and go-ipfs versions <= 0.6.0

NOTE! OrbitDB is alpha-stage software. It means OrbitDB hasn't been security audited and programming APIs and data formats can still change. We encourage you to reach out to the maintainers if you plan to use OrbitDB in mission critical systems.

This is the Javascript implementation and it works both in Browsers and Node.js with support for Linux, OS X, and Windows. Node version 16 is supported.

To use with older versions of Node.js, we provide an ES5-compatible build through the npm package, located in dist/es5/ when installed through npm.

Table of Contents




- API
  Build



Usage


Read the GETTING STARTED guide for a quick tutorial on how to use OrbitDB.

For a more in-depth tutorial and exploration of OrbitDB's architecture, please check out the OrbitDB Field Manual.

Database browser UI


OrbitDB databases can easily be managed using a web UI, see OrbitDB Control Center.

Install and run it locally:

  1. ```
  2. git clone https://github.com/orbitdb/orbit-db-control-center.git
  3. cd orbit-db-control-center/
  4. npm i && npm start
  5. ```

Module with IPFS Instance


If you're using orbit-db to develop browser or Node.js applications, use it as a module with the javascript instance of IPFS

Install dependencies:

  1. ```
  2. npm install orbit-db ipfs
  3. ```


  1. ``` js
  2. const IPFS = require('ipfs')
  3. const OrbitDB = require('orbit-db')

  4. ;(async function () {
  5.   const ipfs = await IPFS.create()
  6.   const orbitdb = await OrbitDB.createInstance(ipfs)

  7.   // Create / Open a database
  8.   const db = await orbitdb.log("hello")
  9.   await db.load()

  10.   // Listen for updates from peers
  11.   db.events.on("replicated", address => {
  12.     console.log(db.iterator({ limit: -1 }).collect())
  13.   })

  14.   // Add an entry
  15.   const hash = await db.add("world")
  16.   console.log(hash)

  17.   // Query
  18.   const result = db.iterator({ limit: -1 }).collect()
  19.   console.log(JSON.stringify(result, null, 2))
  20. })()
  21. ```

Module with IPFS Daemon


Alternatively, you can use ipfs-http-client to useorbit-db with a locally running IPFS daemon. Use this method if you're using orbitd-db to develop backend or desktop applications, eg. with Electron.

Install dependencies:

  1. ```
  2. npm install orbit-db ipfs-http-client
  3. ```

  1. ``` js
  2. const IpfsClient = require('ipfs-http-client')
  3. const OrbitDB = require('orbit-db')

  4. const ipfs = IpfsClient('localhost', '5001')

  5. const orbitdb = await OrbitDB.createInstance(ipfs)
  6. const db = await orbitdb.log('hello')
  7. // Do something with your db.
  8. // Of course, you may want to wrap these in an async function.
  9. ```

API


See API.md for the full documentation.

Examples


Install dependencies

  1. ```
  2. git clone https://github.com/orbitdb/orbit-db.git
  3. cd orbit-db
  4. npm install
  5. ```
Some dependencies depend on native addon modules, so you'll also need to meet node-gyp's installation prerequisites. Therefore, Linux users may need to
  1. ```
  2. make clean-dependencies && make deps
  3. ```
to redo the local package-lock.json with working native dependencies.

Browser example


  1. ```
  2. npm install # if not yet installed
  3. make build
  4. npm run examples:browser # if browser isn't opening, open examples/browser/browser.html in your browser
  5. ```

Using Webpack:
  1. ```
  2. npm install # if not yet installed
  3. make build
  4. npm run examples:browser-webpack # if browser isn't opening, open examples/browser/browser-webpack-example/index.html in your browser
  5. ```


Check the code in examples/browser/browser.html and try the live example.

Node.js example


  1. ```
  2. npm run examples:node
  3. ```


Eventlog

See the code in examples/eventlog.js and run it with:
  1. ```
  2. node examples/eventlog.js
  3. ```

Workshop


We have a field manual which has much more detailed examples and a run-through of how to understand OrbitDB, at orbitdb/field-manual. There is also a workshop you can follow, which shows how to build an app, at orbit-db/web3-workshop.

More examples at examples.

Packages


OrbitDB uses the following modules:


OrbitDB Store Packages


Community-maintained Typescript typings are available here: https://github.com/orbitdb/orbit-db-types

Development


Run Tests

  1. ```
  2. npm test
  3. ```

Build

  1. ```
  2. npm run build
  3. ```

Benchmark

  1. ```
  2. node benchmarks/benchmark-add.js
  3. ```

See benchmarks/ for more benchmarks.

Logging


To enable OrbitDB's logging output, set a global ENV variable called LOG to debug,warn or error:

  1. ```
  2. LOG=debug node <file>
  3. ```

Frequently Asked Questions


We have an FAQ! Go take a look at it. If a question isn't there, open an issue and suggest adding it. We can work on the best answer together.

Are there implementations in other languages?


Yes! Take a look at these implementations:

  - Golang: berty/go-orbit-db

The best place to find out what is out there and what is being actively worked on is likely by asking in the Matrix. If you know of any other repos that ought to be included in this section, please open a PR and add them.

Contributing


Take a look at our organization-wide Contributing Guide. You'll find most of your questions answered there. Some questions may be answered in the FAQ, as well.

If you want to code but don't know where to start, check out the issues labelled "help wanted".

Sponsors


The development of OrbitDB has been sponsored by:


If you want to sponsor developers to work on OrbitDB, please reach out to @haadcode.

License


MIT © 2015-2019 Protocol Labs Inc., Haja Networks Oy