Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Latest commit

 

History

History
executable file
·
137 lines (95 loc) · 3.88 KB

README.header.md

File metadata and controls

executable file
·
137 lines (95 loc) · 3.88 KB

bitcore-wallet-client

NPM Package Build Status Coverage Status

The official client library for [bitcore-wallet-service-zel] (https://github.com/zelcash/bitcore-wallet-service-zel).

Description

This package communicates with BWS Bitcore wallet service zel using the REST API. All REST endpoints are wrapped as simple async methods. All relevant responses from BWS are checked independently by the peers, thus the importance of using this library when talking to a third party BWS instance.

See [Bitcore-wallet] (https://github.com/bitpay/bitcore-wallet) for a simple CLI wallet implementation that relays on BWS and uses bitcore-wallet-client.

Get Started

You can start using bitcore-wallet-client with the command below:

  • via [NPM]: by running npm install https://github.com/zelcash/bitcore-wallet-service-zel.git from your console.

Example

Start your own local Bitcore wallet service zel instance. In this example we assume you have bitcore-wallet-service-zel running on your localhost:3232.

Then create two files irene.js and tomas.js with the content below:

irene.js

var Client = require('bitcore-wallet-client-zel');


var fs = require('fs');
var BWS_INSTANCE_URL = 'https://bws.bitcoinz.ph/bws/api'

var client = new Client({
  baseUrl: BWS_INSTANCE_URL,
  verbose: false,
});

client.createWallet("My Wallet", "Irene", 2, 2, {network: 'testnet'}, function(err, secret) {
  if (err) {
    console.log('error: ',err);
    return
  };
  // Handle err
  console.log('Wallet Created. Share this secret with your copayers: ' + secret);
  fs.writeFileSync('irene.dat', client.export());
});

tomas.js

var Client = require('bitcore-wallet-client-zel');


var fs = require('fs');
var BWS_INSTANCE_URL = 'https://bws.bitcoinz.ph/bws/api'

var secret = process.argv[2];
if (!secret) {
  console.log('./tomas.js <Secret>')

  process.exit(0);
}

var client = new Client({
  baseUrl: BWS_INSTANCE_URL,
  verbose: false,
});

client.joinWallet(secret, "Tomas", {}, function(err, wallet) {
  if (err) {
    console.log('error: ', err);
    return
  };

  console.log('Joined ' + wallet.name + '!');
  fs.writeFileSync('tomas.dat', client.export());


  client.openWallet(function(err, ret) {
    if (err) {
      console.log('error: ', err);
      return
    };
    console.log('\n\n** Wallet Info', ret); //TODO

    console.log('\n\nCreating first address:', ret); //TODO
    if (ret.wallet.status == 'complete') {
      client.createAddress({}, function(err,addr){
        if (err) {
          console.log('error: ', err);
          return;
        };

        console.log('\nReturn:', addr)
      });
    }
  });
});

Install bitcore-wallet-client-zel before start:

npm install https://github.com/zelcash/bitcore-wallet-service-zel.git

Create a new wallet with the first script:

$ node irene.js
info Generating new keys
 Wallet Created. Share this secret with your copayers: JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT

Join to this wallet with generated secret:

$ node tomas.js JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT
Joined My Wallet!

Wallet Info: [...]

Creating first address:

Return: [...]

Note that the scripts created two files named irene.dat and tomas.dat. With these files you can get status, generate addresses, create proposals, sign transactions, etc.