0

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

Hackeerrrr
  • 15
  • 6

1 Answers1

0

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: ['*']
                }
Phillmac
  • 109
  • 7
  • what are the main differences between the two? – Hackeerrrr Jun 24 '20 at 08:33
  • It errors out to `Database '...' is type 'keyvalue' but was opened as 'ipfs'` or `Database '...' is type 'keyvalue' but was opened as 'orbitdb'` – Hackeerrrr Jun 24 '20 at 08:36
  • Seems to work on sandbox io but not on my machine(Windows) – Hackeerrrr Jun 24 '20 at 11:57
  • > what are the main differences between the two? orbitdb access controller allows adding write access to other identities dynamically, ipfs type doesn't – Phillmac Jun 25 '20 at 09:05
  • So if I init orbitdb with ipfs type, other users wont be able to add data to the database? – Hackeerrrr Jun 25 '20 at 09:12
  • The 'ipfs' type acess controller has a static list of users that can write. It's defined when you create the db. The 'orbitdb' type acess controller has the option to add write acess for users at a later time. Using a write access list of '*' means the db is witeable by anyone regardless of the access controller type – Phillmac Jun 26 '20 at 11:05