json-rpc for nSPV, with Promises support
- Supports on-the-fly RPC methods using Proxies; all the RPC methods supported by a nSPV binary are available
- Supports multiple instances (different daemons) in the same application
- Works in browser and Nodejs
- Very small codebase
- Uses axios behind the scenes
-
require()
the module; it imports a class - launch a
new
instance of the class with a config object as the argument; the config object must contain the credentials directly - call
.config
with the new instance object to access its config - call
.rpc()
with the new instance object to access the RPC interface
const SmartChain = require("nspv-rpc-js");
const config = {
rpchost: "localhost",
rpcport: 7771,
};
const komodo = new SmartChain({ config });
console.log(komodo.config); // Prints the config being used by the komodo instance
const komodoRPC = komodo.rpc();
komodoRPC
.getinfo()
.then((info) => {
console.log(info);
})
.catch((error) => {
console.log(error);
throw new Error(error);
});
komodoRPC
.listunspent("RD47yEoA4VGriqjeiLdMVKnuE7x7xqFy9r", false, 5)
.then((outs) => {
console.log(outs.utxos.length);
})
.catch((error) => console.log(error));
Descriptions of the properties
-
HOSTNAME
the address at which the nSPV binary is listening for connections -
PORT
is the port at which the nSPV binary is listening for connections
If the config
object is missing the keys: rpchost
or rpcport
, the default values used are localhost
and 7771
respectively