1.1.17 • Published 11 months ago

@tyz-wallet/tyz-wallet-core-wallet-client v1.1.17

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

tyz-wallet-core-wallet-client

The official client library for TWS.

Description

This package communicates with TWS 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.

Get Started

You can start using tyz-wallet-core-wallet-client: by running npm install @tyz-wallet/tyz-wallet-core-wallet-client from your console.

Example

Start your own local BWS instance. In this example we assume you have tyz-wallet-core-wallet-client running on your localhost:3232.

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

irene.js

var Client = require('@tyz-wallet/tyz-wallet-core-wallet-client');


var fs = require('fs');
var TWS_INSTANCE_URL = 'http://localhost:3232/bws/api'

var client = new Client({
  baseUrl: TWS_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('@tyz-wallet/tyz-wallet-core-wallet-client');


var fs = require('fs');
var TWS_INSTANCE_URL = 'https://localhost:3232/bws/api'

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

  process.exit(0);
}

var client = new Client({
  baseUrl: TWS_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 @tyz-wallet/tyz-wallet-core-wallet-client before start:

npm i @tyz-wallet/tyz-wallet-core-wallet-client

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.

1.1.17

11 months ago

1.1.12

12 months ago

1.1.11

12 months ago

1.1.16

11 months ago

1.1.15

12 months ago

1.1.14

12 months ago

1.1.13

12 months ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago