nodejs 中的 Orbitdb + IPFS

Orbitdb + IPFS in nodejs

我正在尝试将 orbit-db 与 IPFS 一起使用,并且正在阅读 OrbitDB 的官方文档。 ATM,我只是想创建一个数据库(特别是键值存储)并且我现在有以下代码


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)

        }
    }

但无论我尝试什么,我总是收到同样的错误

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

因此,我们将不胜感激。如果缺少任何信息,也请发表评论,我会根据要求添加它

我认为您的 accessController 有一个小问题。 admin 属性 的存在表明你想像这样使用 orbitdb 类型:

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

否则,如果您想使用默认 ipfs 类型,请像这样删除管理员 属性:

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