0.0.2 • Published 4 years ago
nspv-rpc-js v0.0.2
nspv-rpc-js
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
Instructions
require()the module; it imports a class- launch a
newinstance of the class with a config object as the argument; the config object must contain the credentials directly - call
.configwith the new instance object to access its config - call
.rpc()with the new instance object to access the RPC interface
Usage
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
HOSTNAMEthe address at which the nSPV binary is listening for connectionsPORTis the port at which the nSPV binary is listening for connections
Defaults
If the config object is missing the keys: rpchost or rpcport, the default values used are localhost and 7771 respectively