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 (response) { console.log('My balance is %d!', response.balance); })
Payment Response Object Properties:
to
- payment destinations ([string|number])amounts
- payment amounts ([number])from
- from account / address (string|number)fee
- final fee paid in satoshi (number)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)
Account Object Properties:
balance
- the account balance in satoshi (number)label
- the account label (string)index
- the account index (number)archived
- indicates if the account is archived or not (boolean)extendedPublicKey
- account xpub (string)extendedPrivateKey
- account xpriv (string)receiveIndex
- current account receive index (number)lastUsedReceiveIndex
- the last used receive index (number)receivingAddressLabels
- receive address labels ([{number: string}])receiveAddress
- current receive address (string)
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 address (string)label
- label to give to the wallet's first bitcoin address (string)email
- email to associate with the new Blockchain Wallet (string)hd
- create the new wallet as an hd wallet (boolean, recommended)apiHost
- set the host for the api calls to the newly created wallet (string, 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 sendfrom
- send from a specific Bitcoin address or account index (string|number, required when sending from an account)
Options (optional):
fee
- transaction fee value in satoshi (number, defaults to 0.0001btc)feePerByte
- transaction fee in satoshi per byte (number, recommended)
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)from
- send from a specific Bitcoin address or account index (string|number, required when sending from an account)
Options (optional):
fee
- transaction fee value in satoshi (number, defaults to 0.0001btc)feePerByte
- transaction fee in satoshi per byte (number, recommended)
Usage:
wallet.getBalance()
Responds with the entire balance of a wallet, as a number, in satoshi.
Usage:
wallet.enableHD()
Upgrades a legacy wallet to an HD wallet. Responds with an account object (the first account in the new HD wallet).
Usage:
wallet.listAccounts()
Lists wallet HD accounts. Responds with an array of account objects.
Usage:
wallet.listXPubs()
Lists wallet account xpubs. Responds with an array of xpub strings.
Usage:
wallet.createAccount(options)
Creates a new HD account at the next unused account index. Responds with an account object.
Options (optional)
label
- label to give the new account (string)
Usage:
wallet.getAccount(xpubOrIndex)
Gets a single HD account. Responds with an account object.
Parameters:
xpubOrIndex
- the account xpub or index (string|number, required)
Usage:
wallet.getAccountReceiveAddress(xpubOrIndex)
Gets the next unused receive address for an HD account. Responds with an object containing an address property.
Parameters:
xpubOrIndex
- the account xpub or index (string|number, required)
Usage:
wallet.getAccountBalance(xpubOrIndex)
Gets the balance of an HD account. Responds with an object containing a balance property.
Parameters:
xpubOrIndex
- the account xpub or index (string|number, required)
Usage:
wallet.archiveAccount(xpubOrIndex)
Archives an HD account. Responds with an account object.
Parameters:
xpubOrIndex
- the account xpub or index (string|number, required)
Usage:
wallet.unarchiveAccount(xpubOrIndex)
Unarchives an HD account. Responds with an account object.
Parameters:
xpubOrIndex
- the account xpub or index (string|number, required)
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)
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)