bitcore-wallet-client

The official client library for [bitcore-wallet-service] (https://github.com/bitpay/bitcore-wallet-service).
Description
This package communicated to BWS Bitcore wallet service using its REST API. All REST endpoints are wrapped on simple async call. All relevant responses from BWS are checked independently by the peers, thus the importance of using this library with talking with 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
To get going with bitcore-wallet-client you can use one of the following ways:
- via Bower: by running
bower install bitcore-wallet-client
from your console - or via NPM: by running
npm install bitcore-wallet-client
from your console.
Example
Start your own local Bitcore wallet service instance. In this example we suppose that you have bitcore-wallet-service
running on your localhost:3001
.
Then create two files one.js
and two.js
with the follow contents:
one.js
var Client = require('bitcore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3001/copay/api'
var WALLET = 'oneWallet.dat';
var client = new Client({
baseUrl: BWS_INSTANCE_URL,
verbose: false,
});
client.createWallet("My Wallet", "Irene", 2, 2, 'testnet', function(err, secret) {
console.log(' Wallet Created. Share this secret with your copayers: ' + secret);
fs.writeFileSync(WALLET, client.export());
});
two.js
var Client = require('bitcore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3001/copay/api'
var WALLET = 'twoWallet.dat';
var secret = process.argv[2];
var client = new Client({
baseUrl: BWS_INSTANCE_URL,
verbose: false,
});
client.joinWallet(secret, "Thomas", function(err, wallet) {
console.log('Wallet Joined!');
fs.writeFileSync(WALLET, client.export());
});
Install bitcore-wallet-client
before start:
npm i bitcore-wallet-client
Create a new wallet with the first script:
$ node one.js
info Generating new keys
Wallet Created. Share this secret with your copayers: JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT
Join to this wallet with generated secret:
$ node two.js JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT
Wallet Joined!
Note that the scripts created two files named oneWallet.dat
and twoWallet.dat
. With these files you can get status, generate addresses, to send transactions, etc.
API Client
- new API(opts)
- API.seedFromExtendedPrivateKey(xPrivKey)
- API.seedFromRandom(xPrivKey)
- ApI.export(opts)
- ApI.import(opts)
- ApI.toString()
- ApI.fromString(str)
- ApI._doRequest(method, url, args, cb)
- ApI._doPostRequest(url, args, cb)
- ApI._doGetRequest(url, cb)
- API._doDeleteRequest(url, cb)
- API._doJoinWallet(walletId, walletPrivKey, xPubKey, copayerName, cb)
- API.isComplete()
- API.openWallet(cb)
- API.createWallet(walletName, copayerName, m, n, network, cb)
- API.joinWallet(secret, copayerName, cb)
- API.getStatus(cb)
- API.sendTxProposal(opts)
- API.createAddress(cb)
- API.getMainAddresses(opts, cb)
- API.getBalance(cb)
- API.getTxProposals(opts)
- API.getSignatures(opts)
- API.signTxProposal(txp, cb)
- API.rejectTxProposal(txp, reason, cb)
- API.broadcastTxProposal(txp, cb)
- API.removeTxProposal(txp, cb)
- API.getTxHistory(opts, cb)
###new API(opts)
ClientAPI constructor.
Params
###API.seedFromExtendedPrivateKey(xPrivKey)
Seed from extended private key
Params
###API.seedFromRandom(xPrivKey)
Seed from random
Params
###API.export(opts)
Export wallet
Params
- opts
Object
- compressed
Boolean
- password
String
###API.import(opts)
Import wallet
Params
- opts
Object
- compressed
Boolean
- password
String
###API.toString()
Return a serialized object with credentials
###API.fromString(str)
Get credentials from an object
Params
###API._doRequest(method, url, args, cb)
Do a request
Params
- method
Object
- url
String
- args
Object
- cb
Callback
###API._doPostRequest(url, args, cb)
Post a request
Params
- url
String
- args
Object
- cb
Callback
###API._doGetRequest(url, cb)
Get a request
Params
###API._doDeleteRequest(url, cb)
Delete a request
Params
###API._doJoinWallet(walletId, walletPrivKey, xPubKey, copayerName, cb)
Join
Params
- walletId
String
- walletPrivKey
String
- xPubKey
String
- copayerName
String
- cb
Callback
###API.isComplete()
Return if wallet is complete
###API.openWallet(cb)
Opens a wallet and tries to complete the public key ring.
Params
Returns: Callback
- cb - Returns an error and a flag indicating that the wallet has just been completed and needs to be persisted
###API.createWallet(walletName, copayerName, m, n, network, cb)
Create a wallet.
Params
- walletName
String
- copayerName
String
- m
Number
- n
Number
- network
String
- 'livenet' or 'testnet' - cb
Callback
Returns: Callback
- cb - Returns the wallet
###API.joinWallet(secret, copayerName, cb)
Join to an existent wallet
Params
- secret
String
- copayerName
String
- cb
Callback
Returns: Callback
- cb - Returns the wallet
###API.getStatus(cb)
Get status of the wallet
Params
Returns: Callback
- cb - Returns error or an object with status information
###API.sendTxProposal(opts)
Send a transaction proposal
Params
- opts
Object
- toAddress
String
- amount
Number
- message
String
Returns: Callback
- cb - Return error or the transaction proposal
###API.createAddress(cb)
Create a new address
Params
Returns: Callback
- cb - Return error or the address
###API.getMainAddresses(opts, cb)
Get your main addresses
Params
Returns: Callback
- cb - Return error or the array of addresses
###API.getBalance(cb)
Update wallet balance
Params
##API.getTxProposals(opts)
Get list of transactions proposals
Params
- opts
Object
- doNotVerify
Boolean
- forAirGapped
Boolean
Returns: Callback
- cb - Return error or array of transactions proposals
###API.getSignatures(opts)
Get list of transactions proposals
Params
- opts
Object
- doNotVerify
Boolean
- forAirGapped
Boolean
Returns: Callback
- cb - Return error or array of transactions proposals
###API.signTxProposal(txp, cb)
Sign a transaction proposal
Params
Returns: Callback
- cb - Return error or object
###API.rejectTxProposal(txp, reason, cb)
Reject a transaction proposal
Params
- txp
Object
- reason
String
- cb
Callback
Returns: Callback
- cb - Return error or object
###API.broadcastTxProposal(txp, cb)
Broadcast a transaction proposal
Params
Returns: Callback
- cb - Return error or object
###API.removeTxProposal(txp, cb)
Remove a transaction proposal
Params
Returns: Callback
- cb - Return error or empty
###API.getTxHistory(opts, cb)
Get transaction history
Params
Returns: Callback
- cb - Return error or array of transactions