Skip to content

Error in README #53

@farisshajahan

Description

@farisshajahan

The sample code in README throws an error Cannot read property 'then' of undefined

var {Apis} = require("peerplaysjs-lib");
Apis.instance("wss://bitshares.openledger.info/ws").init_promise.then((res) => {
    console.log("connected to:", res[0].network);
    Apis.instance().db_api().exec( "set_subscribe_callback", [ updateListener, true ] )
});

I believe the error is because init_promise is a property of the ApisInstance object only after the connect phase. Apis.instance() only connects to the connection string if a second parameter is provided as true according to the code. Hence modifying the code as below resolves the issue:

var {Apis} = require("peerplaysjs-lib");
Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
    console.log("connected to:", res[0].network);
    Apis.instance().db_api().exec( "set_subscribe_callback", [ updateListener, true ] )
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions