首页 > 解决方案 > nodejs中的Orbitdb + IPFS

问题描述

我正在尝试将 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

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

标签: node.jsipfsorbitdb

解决方案


我认为您的accessController. 该admin属性的存在表明您要使用这样的orbitdb类型:

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

否则,如果您希望使用默认ipfs类型,请删除 admin 属性,如下所示:

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

推荐阅读