0.0.7 • Published 7 years ago

node-dcr-rpc v0.0.7

Weekly downloads
32
License
-
Repository
github
Last release
7 years ago

node-dcrcoin

node-dcrcoin is a simple wrapper for the dcrd and dcrwallet client's JSON-RPC API.

Install

npm install node-dcr-rpc

Examples

Create DCRD client

var dcrd = new dcrcoin.Client({
  host: '127.0.0.1',
  port: 19109, // testnet default port
  user: '',
  pass: '',
  ssl: true
  //,sslCa: fs.readFileSync('~/.dcrd/rpc.cert')
});

Get Info with Method

dcrd.getinfo(function(err, info){
  if (err) return console.log(err);
  console.log('getinfo:', info);
});

Get Info with Command

dcrd.cmd('getinfo', function(err, info){
  if (err) return console.log(err);
  console.log('getinfo:', info);
});

Create Wallet client

var dcrwallet = new dcrcoin.Client({
  host: '127.0.0.1',
  port: 19110, // testnet walltet default port
  user: '',
  pass: '',
  ssl: true
  //,sslCa: fs.readFileSync('~/.dcrd/rpc.cert')
});

Generate New Account and Address

var accountName = "bk_dcr_wallet"
dcrwallet.cmd('createnewaccount', accountName, function(err, wallets){
  if (err) return console.log(err);
  console.log('createenwaccount:', "true");
  dcrwallet.cmd('getnewaddress', accountName, function(err, address){
    if (err) return console.log(err);
    console.log('getnewaddress:', address);
  });
});

List All Accounts

dcrwallet.cmd('listaccounts', function(err, wallets){
  if (err) return console.log(err);
  console.log('listaccounts:', wallets);
});

Using DCRD and DCRWALLET in same Client

var dcrdAndDcrWallet = new dcrcoin.Client({
  host: '127.0.0.1',
  dcrdPort: 19109, // dcrd port
  dcrWalletPort: 19110, // dcrwallet port
  user: 'brunokenj',
  pass: 'J6BINJBX5pCnrr1P5RO87na3DNLPsvv/',
  ssl: true
  //,sslCa: fs.readFileSync('~/.dcrd/rpc.cert')
});

dcrdAndDcrWallet.getinfo(function(err, info) {
  if (err) return console.log(err);
  console.log('info:', info);
});

dcrdAndDcrWallet.wallet.listaccounts(function (err, accounts) {
  if (err) return console.log(err);
  console.log('listaccounts:', accounts);
});

Forked

forked from brunokenj/node-ethcoin

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago