Class: Wallet

wallet~Wallet(options)

Wallet

Constructor

new Wallet(options)

Create a wallet.

Extends:
  • EventEmitter
Parameters:
Name Type Description
options Object
Source:

Extends

  • EventEmitter

Methods

(static) fromOptions(wdb, options) → {Wallet}

Instantiate wallet from options.

Parameters:
Name Type Description
wdb WalletDB
options Object
Source:
Returns:
Type
Wallet

(static) fromRaw(data) → {Wallet}

Instantiate a wallet from serialized data.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
Wallet

(static) isWallet(obj) → {Boolean}

Test an object to see if it is a Wallet.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

(private) _abandon(hash) → {Promise}

Abandon transaction without a lock.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async, private) _add(tx) → {Promise}

Add a transaction to the wallet without a lock. Potentially resolves orphans.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

(async, private) _addSharedKey(acct, key) → {Promise}

Add a public account key to the wallet without a lock.

Parameters:
Name Type Description
acct Number | String
key HDPublicKey
Source:
Returns:
Type
Promise

(async) _createAccount(options) → {Promise}

Create an account without a lock.

Parameters:
Name Type Description
options Object

See Account options.

Source:
Returns:
  • Returns Account.
Type
Promise

(async, private) _createKey(acctnullable, branch) → {Promise}

Create a new address (increments depth) without a lock.

Parameters:
Name Type Attributes Description
acct Number | String <nullable>
branch Number
Source:
Returns:
  • Returns WalletKey.
Type
Promise

(async, private) _decrypt(passphrase) → {Promise}

Decrypt the wallet permanently, without a lock.

Parameters:
Name Type Description
passphrase String | Buffer
Source:
Returns:
Type
Promise

(async, private) _encrypt(passphrase) → {Promise}

Encrypt the wallet permanently, without a lock.

Parameters:
Name Type Description
passphrase String | Buffer
Source:
Returns:
Type
Promise

(async, private) _fund()

Fill a transaction with inputs without a lock.

Source:
See:
  • MTX#selectCoins
  • MTX#fill

(async) _getPendingAncestors(tx, set) → {Promise}

Get pending ancestors up to the policy limit.

Parameters:
Name Type Description
tx TX
set Object
Source:
Returns:
  • Returns {BufferSet} with Hash
Type
Promise

(async, private) _importAddress(acctnullable, ring, passphrasenullable) → {Promise}

Import a keyring (will not exist on derivation chain) without a lock.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
ring WalletKey
passphrase String | Buffer <nullable>
Source:
Returns:
Type
Promise

(async, private) _importKey(acctnullable, ring, passphrasenullable) → {Promise}

Import a keyring (will not exist on derivation chain) without a lock.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
ring WalletKey
passphrase String | Buffer <nullable>
Source:
Returns:
Type
Promise

(async, private) _removeSharedKey(acct, key) → {Promise}

Remove a public account key from the wallet (multisig).

Parameters:
Name Type Description
acct Number | String
key HDPublicKey
Source:
Returns:
Type
Promise

(async, private) _renameAccount(acctnullable, name) → {Promise}

Rename account without a lock.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
name String
Source:
Returns:
Type
Promise

(async, private) _retoken(passphrasenullable) → {Promise}

Generate a new token without a lock.

Parameters:
Name Type Attributes Description
passphrase String | Buffer <nullable>
Source:
Returns:
Type
Promise

(async, private) _send(options) → {Promise}

Build and send a transaction without a lock.

Parameters:
Name Type Description
options Object

See options.

Properties
Name Type Description
outputs Array.<Object>

See MTX#addOutput.

Source:
Returns:
  • Returns TX.
Type
Promise

(async, private) _setLookahead(accountnullable, lookahead) → {Promise}

Increase lookahead for account (without a lock).

Parameters:
Name Type Attributes Description
account Number | String <nullable>
lookahead Number
Source:
Returns:
Type
Promise

(async, private) _zap(acctnullable, age) → {Promise}

Zap stale TXs from wallet without a lock.

Parameters:
Name Type Attributes Description
acct Number | String <nullable>
age Number
Source:
Returns:
Type
Promise

(async) abandon(hash) → {Promise}

Abandon transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async) accountKey(acctopt) → {HDPublicKey}

Get account key.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
HDPublicKey

(async) add(tx) → {Promise}

Add a transaction to the wallets TX history.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

(async) addSharedKey(acct, key) → {Promise}

Add a public account key to the wallet (multisig). Saves the key in the wallet database.

Parameters:
Name Type Description
acct Number | String
key HDPublicKey
Source:
Returns:
Type
Promise

(async) changeAddress(acctopt) → {Address}

Get current change address.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
Address

(async) changeDepth(acctopt) → {Number}

Get current change depth.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
Number

(async) changeKey(acctopt) → {WalletKey}

Get current change key.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
WalletKey

(async) createAccount(options) → {Promise}

Create an account. Requires passphrase if master key is encrypted.

Parameters:
Name Type Description
options Object

See Account options.

Source:
Returns:
  • Returns Account.
Type
Promise

createChange(acctnullable) → {Promise}

Create a new change address (increments receiveDepth).

Parameters:
Name Type Attributes Default Description
acct Number | String <nullable>
0
Source:
Returns:
  • Returns WalletKey.
Type
Promise

(async) createKey(acctnullable, branch) → {Promise}

Create a new address (increments depth).

Parameters:
Name Type Attributes Description
acct Number | String <nullable>
branch Number
Source:
Returns:
  • Returns WalletKey.
Type
Promise

createNested(acctnullable) → {Promise}

Create a new nested address (increments receiveDepth).

Parameters:
Name Type Attributes Default Description
acct Number | String <nullable>
0
Source:
Returns:
  • Returns WalletKey.
Type
Promise

createReceive(acctnullable) → {Promise}

Create a new receiving address (increments receiveDepth).

Parameters:
Name Type Attributes Default Description
acct Number | String <nullable>
0
Source:
Returns:
  • Returns WalletKey.
Type
Promise

(async) createTX(options) → {Promise}

Build a transaction, fill it with outputs and inputs, sort the members according to BIP69 (set options.sort=false to avoid sorting), set locktime, and template it.

Parameters:
Name Type Description
options Object

See options.

Properties
Name Type Description
outputs Array.<Object>

See MTX#addOutput.

sort Boolean

Sort inputs and outputs (BIP69).

template Boolean

Build scripts for inputs.

locktime Number

TX locktime

Source:
Returns:
  • Returns MTX.
Type
Promise

(async) decrypt(passphrase) → {Promise}

Decrypt the wallet permanently.

Parameters:
Name Type Description
passphrase String | Buffer
Source:
Returns:
Type
Promise

(async) deriveInputs(mtx, indexnullable) → {Promise}

Derive necessary addresses for signing a transaction.

Parameters:
Name Type Attributes Description
mtx MTX
index Number <nullable>

Input index.

Source:
Returns:
  • Returns WalletKey[].
Type
Promise

(async) destroy() → {Promise}

Close the wallet, unregister with the database.

Source:
Returns:
Type
Promise

(async) encrypt(passphrase) → {Promise}

Encrypt the wallet permanently.

Parameters:
Name Type Description
passphrase String | Buffer
Source:
Returns:
Type
Promise

(async) ensureAccount(options) → {Promise}

Ensure an account. Requires passphrase if master key is encrypted.

Parameters:
Name Type Description
options Object

See Account options.

Source:
Returns:
  • Returns Account.
Type
Promise

(async) ensureIndex(acct) → {Promise}

Lookup the corresponding account name's index.

Parameters:
Name Type Description
acct String | Number

Account name/index.

Source:
Throws:

on non-existent account

Returns:
  • Returns Number.
Type
Promise

(async) estimateSize(prev) → {Number}

Input size estimator for max possible tx size.

Parameters:
Name Type Description
prev Script
Source:
Returns:
Type
Number

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options Object
Source:

(private) fromRaw(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:

(async) fund(mtx, optionsnullable)

Fill a transaction with inputs, estimate transaction size, calculate fee, and add a change output.

Parameters:
Name Type Attributes Description
mtx MTX

Must be a mutable transaction.

options Object <nullable>
Properties
Name Type Attributes Description
account String | Number <nullable>

If no account is specified, coins from the entire wallet will be filled.

selection String <nullable>

Coin selection priority. Can be age, random, or all. (default=age).

round Boolean

Whether to round to the nearest kilobyte for fee calculation. See TX#getMinFee vs. TX#getRoundFee.

rate Rate

Rate used for fee calculation.

confirmed Boolean

Select only confirmed coins.

free Boolean

Do not apply a fee if the transaction priority is high enough to be considered free.

hardFee Amount <nullable>

Use a hard fee rather than calculating one.

subtractFee Number | Boolean

Whether to subtract the fee from existing outputs rather than adding more inputs.

Source:
See:
  • MTX#selectCoins
  • MTX#fill

(async) getAccount(acct) → {Promise}

Retrieve an account from the database.

Parameters:
Name Type Description
acct Number | String
Source:
Returns:
  • Returns Account.
Type
Promise

(async) getAccountByAddress(address) → {Account}

Get account by address.

Parameters:
Name Type Description
address Address
Source:
Returns:
Type
Account

(async) getAccountHashes(acct) → {Promise}

Get all account address hashes.

Parameters:
Name Type Description
acct String | Number
Source:
Returns:
  • Returns Array.
Type
Promise

getAccountIndex(acct) → {Promise}

Lookup the corresponding account name's index.

Parameters:
Name Type Description
acct String | Number

Account name/index.

Source:
Returns:
  • Returns Number.
Type
Promise

(async) getAccountName(index) → {Promise}

Lookup the corresponding account index's name.

Parameters:
Name Type Description
index Number

Account index.

Source:
Returns:
  • Returns String.
Type
Promise

(async) getAccountPaths(acct) → {Promise}

Get all account paths.

Parameters:
Name Type Description
acct String | Number
Source:
Returns:
  • Returns Path.
Type
Promise

getAccounts() → {Promise}

List account names and indexes from the db.

Source:
Returns:
  • Returns Array.
Type
Promise

getAddressHashes(acctnullable) → {Promise}

Get all wallet address hashes.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
Source:
Returns:
  • Returns Array.
Type
Promise

(async) getBalance(acctnullable) → {Promise}

Get wallet balance.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
Source:
Returns:
  • Returns Balance.
Type
Promise

getBlock(height) → {Promise}

Get a block from the wallet.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

getBlocks() → {Promise}

List blocks for the wallet.

Source:
Returns:
Type
Promise

getCoin(hash, index) → {Promise}

Get a coin from the wallet.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Coin.
Type
Promise

(async) getCoins(accountnullable) → {Promise}

Get all available coins.

Parameters:
Name Type Attributes Description
account String | Number <nullable>
Source:
Returns:
  • Returns Coin[].
Type
Promise

getCoinView(tx) → {Promise}

Get a coin viewpoint.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async) getCredits(accountnullable) → {Promise}

Get all available credits.

Parameters:
Name Type Attributes Description
account String | Number <nullable>
Source:
Returns:
  • Returns Credit[].
Type
Promise

getDetails(hash) → {Promise}

Get transaction details.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Details.
Type
Promise

(async) getHistory(acctnullable) → {Promise}

Get all transactions in transaction history.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
Source:
Returns:
  • Returns TX[].
Type
Promise

(private) getID() → {Base58String}

Generate the wallet ID if none was passed in. It is represented as HASH160(m/44->public|magic) converted to an "address" with a prefix of 0x03be04 (WLT in base58).

Source:
Returns:
Type
Base58String

(async) getInputPaths(mtx) → {Promise}

Map input addresses to paths.

Parameters:
Name Type Description
mtx MTX
Source:
Returns:
  • Returns Path[].
Type
Promise

(async) getKey(hash) → {Promise}

Retrieve a single keyring by address.

Parameters:
Name Type Description
hash Address | Hash
Source:
Returns:
Type
Promise

(async) getLast(acctnullable, limit) → {Promise}

Get the last N transactions.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
limit Number
Source:
Returns:
  • Returns TX[].
Type
Promise

getLocked() → {Array.<Outpoint>}

Return an array of all locked outpoints.

Source:
Returns:
Type
Array.<Outpoint>

(async) getOutputPaths(tx) → {Promise}

Map output addresses to paths.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns Path[].
Type
Promise

(async) getPath(address) → {Promise}

Get path by address hash.

Parameters:
Name Type Description
address Address | Hash
Source:
Returns:
  • Returns Path.
Type
Promise

(async) getPaths(acctnullable) → {Promise}

Get all wallet paths.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
Source:
Returns:
  • Returns Path.
Type
Promise

(async) getPending(acctnullable) → {Promise}

Get all pending/unconfirmed transactions.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
Source:
Returns:
  • Returns TX[].
Type
Promise

(async) getPendingAncestors(tx) → {Promise}

Get pending ancestors up to the policy limit

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns {BufferSet} with Hash
Type
Promise

(async) getPrivateKey(hash, passphrasenullable) → {Promise}

Retrieve a single keyring by address (with the private key reference).

Parameters:
Name Type Attributes Description
hash Address | Hash
passphrase Buffer | String <nullable>
Source:
Returns:
Type
Promise

(async) getRange(acctnullable, options) → {Promise}

Get a range of transactions between two timestamps.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
options Object
Properties
Name Type Description
start Number
end Number
Source:
Returns:
  • Returns TX[].
Type
Promise

getSize() → {Number}

Calculate serialization size.

Source:
Returns:
Type
Number

(async) getSmartCoins(accountnullable) → {Promise}

Get "smart" coins.

Parameters:
Name Type Attributes Description
account String | Number <nullable>
Source:
Returns:
  • Returns Coin[].
Type
Promise

getSpentView(tx) → {Promise}

Get a historical coin viewpoint.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns CoinView.
Type
Promise

(private) getToken(master, nonce) → {Buffer}

Generate the wallet api key if none was passed in. It is represented as HASH256(m/44'->private|nonce).

Parameters:
Name Type Description
master HDPrivateKey
nonce Number
Source:
Returns:
Type
Buffer

getTX(hash) → {Promise}

Get a transaction from the wallet.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns TX.
Type
Promise

(async) hasAccount(acct) → {Promise}

Test whether an account exists.

Parameters:
Name Type Description
acct Number | String
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) hasAddress(address) → {Promise}

Test whether the wallet possesses an address.

Parameters:
Name Type Description
address Address | Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) hasPath(address) → {Promise}

Test whether the wallet contains a path.

Parameters:
Name Type Description
address Address | Hash
Source:
Returns:
  • Returns {Boolean}.
Type
Promise

hasPending(hash) → {Promise}

Test whether the database has a pending transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) importAddress(acctnullable, ring, passphrasenullable) → {Promise}

Import a keyring (will not exist on derivation chain). Rescanning must be invoked manually.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
ring WalletKey
passphrase String | Buffer <nullable>
Source:
Returns:
Type
Promise

(async) importKey(acctnullable, ring, passphrasenullable) → {Promise}

Import a keyring (will not exist on derivation chain). Rescanning must be invoked manually.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
ring WalletKey
passphrase String | Buffer <nullable>
Source:
Returns:
Type
Promise

(async) increaseFee(hash, rate, passphrasenullable) → {Promise}

Intentionally double-spend outputs by increasing fee for an existing transaction.

Parameters:
Name Type Attributes Description
hash Hash
rate Rate
passphrase String | Buffer <nullable>
Source:
Returns:
  • Returns TX.
Type
Promise

increment() → {Promise}

Increment the wid depth.

Source:
Returns:
Type
Promise

(async) init() → {Promise}

Attempt to intialize the wallet (generating the first addresses along with the lookahead addresses). Called automatically from the walletdb.

Source:
Returns:
Type
Promise

inspectSymbol() → {Object}

Convert the wallet to a more inspection-friendly object.

Source:
Returns:
Type
Object

isLocked(coin)

Test locked status of a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

(async) lock()

Lock the wallet, destroy decrypted key.

Source:

lockCoin(coin)

Lock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

(async) nestedAddress(acctopt) → {Address}

Get current nested address.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
Address

(async) nestedDepth(acctopt) → {Number}

Get current nested depth.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
Number

(async) nestedKey(acctopt) → {WalletKey}

Get current nested key.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
WalletKey

(async) open() → {Promise}

Open wallet (done after retrieval).

Source:
Returns:
Type
Promise

(async, private) readPath(address) → {Promise}

Get path by address hash (without account name).

Parameters:
Name Type Description
address Address | Hash
Source:
Returns:
  • Returns Path.
Type
Promise

(async) receiveAddress(acctopt) → {Address}

Get current receive address.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
Address

(async) receiveDepth(acctopt) → {Number}

Get current receive depth.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
Number

(async) receiveKey(acctopt) → {WalletKey}

Get current receive key.

Parameters:
Name Type Attributes Default Description
acct Number <optional>
0
Source:
Returns:
Type
WalletKey

(async) remove(hash) → {Promise}

Remove a wallet transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async) removeSharedKey(acct, key) → {Promise}

Remove a public account key from the wallet (multisig).

Parameters:
Name Type Description
acct Number | String
key HDPublicKey
Source:
Returns:
Type
Promise

(async) rename(id) → {Promise}

Rename the wallet.

Parameters:
Name Type Description
id String
Source:
Returns:
Type
Promise

(async) renameAccount(acctnullable, name) → {Promise}

Rename account.

Parameters:
Name Type Attributes Description
acct String | Number <nullable>
name String
Source:
Returns:
Type
Promise

(async) resend() → {Promise}

Resend pending wallet transactions.

Source:
Returns:
Type
Promise

(async) retoken(passphrasenullable) → {Promise}

Generate a new token.

Parameters:
Name Type Attributes Description
passphrase String | Buffer <nullable>
Source:
Returns:
Type
Promise

(async) revert(height) → {Promise}

Revert a block.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

save() → {Promise}

Save the wallet to the database. Necessary when address depth and keys change.

Source:
Returns:
Type
Promise

(async) send(options) → {Promise}

Build a transaction, fill it with outputs and inputs, sort the members according to BIP69, set locktime, sign and broadcast. Doing this all in one go prevents coins from being double spent.

Parameters:
Name Type Description
options Object

See options.

Properties
Name Type Description
outputs Array.<Object>

See MTX#addOutput.

Source:
Returns:
  • Returns TX.
Type
Promise

(async) setLookahead(accountnullable, lookahead) → {Promise}

Increase lookahead for account.

Parameters:
Name Type Attributes Description
account Number | String <nullable>
lookahead Number
Source:
Returns:
Type
Promise

(async) setPassphrase(passphrase, old) → {Promise}

Change or set master key's passphrase.

Parameters:
Name Type Description
passphrase String | Buffer
old String | Buffer
Source:
Returns:
Type
Promise

(async) sign(tx, options) → {Promise}

Build input scripts and sign inputs for a transaction. Only attempts to build/sign inputs that are redeemable by this wallet.

Parameters:
Name Type Description
tx MTX
options Object | String | Buffer

Options or passphrase.

Source:
Returns:
  • Returns Number (total number of inputs scripts built and signed).
Type
Promise

(async) syncOutputDepth(tx) → {Promise}

Sync address depths based on a transaction's outputs. This is used for deriving new addresses when a confirmed transaction is seen.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

(async) template(mtx) → {Promise}

Build input scripts templates for a transaction (does not sign, only creates signature slots). Only builds scripts for inputs that are redeemable by this wallet.

Parameters:
Name Type Description
mtx MTX
Source:
Returns:
  • Returns Number (total number of scripts built).
Type
Promise

toDetails(wtx) → {Promise}

Convert transaction to transaction details.

Parameters:
Name Type Description
wtx TXRecord
Source:
Returns:
  • Returns Details.
Type
Promise

toJSON(unsafenullable) → {Object}

Convert the wallet to an object suitable for serialization.

Parameters:
Name Type Attributes Description
unsafe Boolean <nullable>

Whether to include the master key in the JSON.

Source:
Returns:
Type
Object

toRaw() → {Buffer}

Serialize the wallet.

Source:
Returns:
Type
Buffer

unlock(passphrase, timeoutopt, nullable)

Unlock the key for timeout seconds.

Parameters:
Name Type Attributes Default Description
passphrase Buffer | String
timeout Number <optional>
<nullable>
60
Source:

unlockCoin(coin)

Unlock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

unlockCoins()

Unlock all locked coins.

Source:

(async) zap(acctnullable, age) → {Promise}

Zap stale TXs from wallet.

Parameters:
Name Type Attributes Description
acct Number | String <nullable>
age Number

Age threshold (unix time).

Source:
Returns:
Type
Promise