This is a Go implementation of the OrbitDB example that mimics the functionality of the JS version.
- Go 1.16 or higher
- A running IPFS daemon
- Start an IPFS daemon:
ipfs daemon
- Build the example:
go build -o orbitdb-example ./cmd/orbitdb-example
./orbitdb-example -data ./data/mynode
-data
: Data directory path (default: "./data")-db
: OrbitDB address to connect to (if connecting to an existing database)-listen
: Libp2p listen address (default: "/ip4/0.0.0.0/tcp/4001")-ipfs
: IPFS API endpoint (default: "localhost:5001")
Use the provided script to run three nodes that will automatically connect:
chmod +x scripts/run_nodes.sh
./scripts/run_nodes.sh
This will:
- Start the first node that creates a new database
- Extract the database address from the logs
- Start two more nodes that connect to the same database
- Output logs to node1.log, node2.log, and node3.log
- Start the first node to create a new database:
./orbitdb-example -data ./data/node1 -listen "/ip4/0.0.0.0/tcp/4001"
-
Note the database address from the logs (e.g.,
/orbitdb/QmYourCID/onmydisk
) -
Start additional nodes connecting to the same database:
./orbitdb-example -data ./data/node2 -listen "/ip4/0.0.0.0/tcp/4002" -db "/orbitdb/QmYourCID/onmydisk"
- The application creates or loads a peer identity
- It connects to a local IPFS node
- It sets up a libp2p host
- It creates or connects to an OrbitDB database
- When connected, it adds a random text to IPFS and stores the CID in OrbitDB
- It listens for updates to the database and fetches files from IPFS when new entries are added
- On shutdown, it prints the final state of the database
MIT