**NOTE: in this example user that runs ipfs and orbitdb instance is nodemaster, also the ipfs location is at /usr/local/bin/ipfs**
> Enable the service
```sh
$ sudo systemctl daemon-reload
$ sudo systemctl enable ipfs.service
$ sudo systemctl start publicNode.service
$ sudo systemctl status ipfs.service
```
**NOTE: service must be set as active (running), if not please verify the preview steps**
# [OrbitDB](https://github.com/orbitdb/orbit-db)
OrbitDB is a **serverless, distributed, peer-to-peer database**. OrbitDB uses [IPFS](https://ipfs.io) as its data storage and [IPFS Pubsub](https://github.com/ipfs/go-ipfs/blob/master/core/commands/pubsub.go#L23) to automatically sync databases with peers. It's an eventually consistent database that uses [CRDTs](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) for conflict-free database merges making OrbitDB an excellent choice for decentralized apps (dApps), blockchain applications and offline-first web applications.
**Start IPFS Daemon** (Note: pubsub-experiment is necesary to work with OrbitDB)
```sh
$ ipfs daemon --enable-pubsub-experiment
```
**Start the DecaCC Interface**
```sh
$ node interfaz.js
```
**Note: With this you can use OrbitDB but only in your local node**
## Usage with replication
You need to do all the past steps.
Run index.js with uncomment line 24, 25, the first log is your orbitdb address (See the Wiki for more information), the second is your orbitDB address database copy this address and pass in index.js in line 6, and in interfaz.js in the same line.
**If you want to debug orbitdb in bash**
```sh
$ export LOG="orbit*" node
```
**Start the DecaCC replicated**
```sh
$ node index.js
```
Later in the nodes that will work like peers only, install the requeriments and run index.js with the new address.
**Start the DecaCC Interface**
```sh
$ node interfaz.js
```
In the node that can write run interfaz.js and choose an option.
```sh
$ Show Carbon Credit records
$ Insert Carbon credit
$ Delete Carbon credit
$ Exit
```
**Note: If the nodes will replicated you need connect before with IPFS Daemon (See Wiki).**
*Note 2: Remember dont lost your orbitdb folder because your identity.id change and cant write in a database another time*
## Connect Nodes
In order to connect nodes, we create a bash script which resolves the domain name of each node and ipfs swarms them,
this script should be configured in a crontab to run every 5 minutes. The crontab should be configured as the user
that holds this repository and that runs the orbitdb.
*Open the crontab as the user that holds the script*
```sh
$ crontab -e
```
*Append the following line at the end of the editor and write it*