Programmatically interact with your Blockchain.info wallet. View full API documentation.
Importing:
var MyWallet = require('blockchain.info/MyWallet');An instance of a wallet needs to be initialized before it can be used:
var wallet = new MyWallet(identifier, password, options);Options:
secondPassword- second wallet password (required only if wallet is double-encrypted)apiCode- Blockchain.info api code (will be automatically included in all further requests to the wallet)apiHost- set the host for the api calls (required)
This module requires the Wallet API v2 service. To use the wallet service for api calls, set the apiHost option to point to where the service is running.
Example:
var options = { apiCode: 'myAPICode', apiHost: 'http://localhost:3000' };
var wallet = new MyWallet('myIdentifier', 'myPassword123', options);
wallet.getBalance().then(function (balance) { console.log('My balance is %d!', balance); });Payment Response Object Properties:
message- message confirming the transaction (string)tx_hash- the hash of the transaction (string)notice- notice, not always returned (string)
Address Object Properties:
address- the address name (string)balance- the address balance in satoshi (number)label- the address label (string or null)total_received- the total satoshi ever received by the address (number)
Usage:
MyWallet.create(password, apiCode, options);Create a new Blockchain Wallet. Responds with an instance of MyWallet, which will adopt the same api code used to create the wallet. If you are using the Wallet API v2 service, remember to set the apiHost option to wherever the service is running.
Parameters:
password- password to set for the wallet (required, must be greater than 10 characters)apiCode- Blockchain.info api code (required)
Options:
priv- private key to use for the wallet's first bitcoin addresslabel- label to give to the wallet's first bitcoin addressemail- email to associate with the new Blockchain WalletapiHost- set the host for the api calls to the newly created wallet (required)
The API code passed into the MyWallet constructor is automatically included in all requests to the wallet.
Usage:
wallet.send(address, amount, options);Sends bitcoin from the wallet to a given address. Responds with a Payment Response Object.
Parameters:
address- bitcoin address to send toamount- amount in satoshi to send
Options (optional):
from- send from a specific Bitcoin address (string)fee- transaction fee value in satoshi (number, defaults to 0.0001btc)note- public note to include with transaction (string, transaction must be > 0.005btc)
Usage:
wallet.sendMany(recipients, options);Sends bitcoin to multiple addresses. Responds with a Payment Response Object.
Parameters:
recipients- object with properties/values in the format: "receivingAddress":amount (required)
Options (optional):
from- send from a specific Bitcoin address (string)fee- transaction fee value in satoshi (number, defaults to 0.0001btc)note- public note to include with transaction (string, transactions must be > 0.005btc)
Usage:
wallet.getBalance();Responds with the entire balance of a wallet, as a number, in satoshi.
Usage:
wallet.listAddresses();Responds with an object that has an addresses property. This property is an array of Address Objects.
Usage:
wallet.getAddress(address, options);
Responds with an address object of the specified address.
Parameters:
address- the name of the address (string)
Options (optional):
confirmations- minimum number of confirmations to check for (number, defaults to 6)
Usage:
wallet.newAddress(options);Creates a new address. Responds with a partial Address Object (contains just the address property, also contains the label property if a label parameter was passed).
Options (optional):
label- automatically set the label of the new address (string)
Usage:
wallet.archiveAddress(address);Archives a specific address. Responds with an object that has the property archived, which is set to the name of the archived address (string).
Parameters:
address- the name of the address to archive (string)
Usage:
wallet.unarchiveAddress(address);Unarchives a specific address. Responds with an object that has the property active, which is set to the name of the unarchived address (string).
Parameters:
address- the name of the address to unarchive (string)
Usage:
wallet.consolidate(options);Consolidates addresses that have not received transactions recently into a single new address, which is automatically added to the wallet. Responds with an object that has the property consolidated, which is set to an array of the names of all addresses that were consolidated (string).
Options (optional):
days- addresses which have not received any transactions in at least this many days will be consolidated (number, defaults to 60)