Search code examples
node.jsipfsorbitdb

Orbitdb + IPFS in nodejs


I am trying to use orbit-db along with the IPFS and I am going through the official documentation of OrbitDB. ATM, I am simply trying to create a db(specifically key-value store) and I have the following code uptil now


const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')

createDb = async() => {

        try {
            const ipfsOptions = {
                config: {
                  my-config-options
                },
                EXPERIMENTAL: {
                  pubsub: true
                }
            }

            const ipfs = await IPFS.create(ipfsOptions)            
            const orbitdb = await OrbitDB.createInstance(ipfs)
            const db = await orbitdb.create('test', 'keyvalue', {
                overwrite: false,
                replicate: true,
                accessController: {
                    admin: ['*'],
                    write: ['*']
                }
            })
            console.log(db)
            await db.put('hello', { name: 'world' })
            console.log(db.all)
        } catch (error) {
            console.trace(error)

        }
    }

But I keep getting the same error no matter what I try

Trace: Error: Could not append entry, key "..." is not allowed to write to the log

So any help would be much appreciated. Also do comment if any information is missing and I would add it as per the requirements


Solution

  • I think there's a small issue with your accessController. The presence of the admin property indicates that you want to use the orbitdb type like this:

                    accessController: {
                        type: 'orbitdb',
                        admin: ['*'],
                        write: ['*']
                    }
    

    Otherwise if you wish to use the default ipfs type, remove the admin property like this:

                    accessController: {
                        type: 'ipfs',
                        write: ['*']
                    }