Skip to content

Dash Client Library to connect to Dash Core (dashd) via RPC

License

Notifications You must be signed in to change notification settings

dashhive/DashRPC.js

Repository files navigation

NPM Package

Dash Client Library to connect to Dash Core (dashd) via RPC

Install

dashd-rpc runs on node, and can be installed via npm:

npm install --save dashrpc

Usage

You can examine DashRpc.callspec to see the list of supported RPCs:

console.info('Supported RPCs:');
console.info(DashRpc.callspec);

If any of them are out of date with Dash: Docs: RPCs: Quick Reference, feel free to open an issue or PR.

DashRpc

Config parameters :

- protocol : (string - optional) - (default: 'https') - Set the protocol to be used. Either `http` or `https`.
- user : (string - optional) - (default: 'user') - Set the user credential.
- pass : (string - optional) - (default: 'pass') - Set the password credential.
- host : (string - optional) - (default: '127.0.0.1') - The host you want to connect with.
- port : (integer - optional) - (default: 9998) - Set the port on which perform the RPC command.

Examples

Config:

var config = {
  protocol: 'http',
  user: 'dash',
  pass: 'local321',
  host: '127.0.0.1',
  port: 19998,
  onconnected: function () {
    console.info('[dashrpc] connected to `${config.host:config.port}`');
  },
};
var DashRpc = require('dashrpc');
var rpc = DashRpc.create(config);

async function main() {
  let height = await rpc.init({ retry: 5000 });
  console.info(`[dashrpc] best block height is ${height}`);

  let rawMempool = await rpc.getRawMemPool();
  for (let result of rawMempool.result) {
    let rawTx = await rpc.getRawTransaction(r);
    console.info(`RawTX: ${rawTx.result}`);
  }
}

main
  .then(function () {
    process.exit(0);
  })
  .catch(function (err) {
    console.error(err);
    process.exit(1);
  });

Help

You can dynamically access to the help of each method by doing

const DashRpc = require('dashrpc');
var client = DashRpc.create({
    protocol:'http',
    user: 'dash',
    pass: 'local321',
    host: '127.0.0.1',
    port: 19998,
    timeout: 1000
});

// Get full help
{
    let help = client.help();
    console.log(help)
}

// Get help of specific method
{
    let getinfoHelp = client.help('getinfo');
    console.log(getinfoHelp)
}

License

This was originally forked from https://github.com/dashpay/dashd-rpc, but has since become its own project.

© 2024-Present Dash Incubator
© 2013-2022 Dash Core Group, Inc.

MIT

About

Dash Client Library to connect to Dash Core (dashd) via RPC

Resources

License

Stars

Watchers

Forks

Packages

No packages published