IPFS не является конструктором: Nodejs - чат IPFS / OrbitDB - PullRequest
1 голос
/ 06 апреля 2020

Я пытаюсь создать Dapp с Nodejs и IPFS / OrbitDB каждый раз, пытаюсь запустить свое приложение, я получаю сообщение об ошибке:

this.node = new IPFS ({ ^

Ошибка типа: IPFS не является конструктором

Это мой базовый c код без указания c Рой:

const Ipfs = require('ipfs');
const OrbitDB = require('orbit-db');

class chatroom {
    constructor(IPFS, OrbitDB) {
        this.OrbitDB = OrbitDB;
        this.node = new IPFS({
            preload: {enable: false},
            repo: "./ipfs",
            EXPERIMENTAL: {pubsub: true},
            config: {
                Bootstrap: [],
                Addresses: {Swarm: []}
            }
        });
        this.node.on("error", (e) => {throw (e)});
        this.node.on("ready", this._init.bind(this));
    }
    async _init(){
        this.orbitdb = await this.OrbitDB.createInstance(this.node);
        this.onready();
    }
}

module.exports = exports = new chatroom(Ipfs, OrbitDB);

Я работаю на следующей версии IPFS: ipfs@0.42.0

Я пробовал это также на пустом Nodejs приложении, и там у меня была такая же ошибка, когда я добавил специфический c Рой, чтобы подключиться.

Я был бы очень признателен за вашу помощь, спасибо за ваше время заранее.

С уважением

Бени

1 Ответ

1 голос
/ 21 апреля 2020

Я сделал это сейчас так:

const IPFS = require('ipfs');

async function createNode() {
        let node = await IPFS.create(
            {
                repo: (() => `repo-${Math.random()}`)(),
                    "Addresses": {
                        "Swarm": [
                            "/ip4/0.0.0.0/tcp/4001"
                        ],
                        "API": "/ip4/127.0.0.1/tcp/5001",
                        "Gateway": "/ip4/127.0.0.1/tcp/8080"
                    }
            }
            );
        try {
            await node.start();
            console.log('Node started!');
        } catch (error) {
            console.error('Node failed to start!', error);
        }
    }

(thx @Eugene)

...