Class: Wallet

wallet.Wallet

new Wallet(options)

BIP44 Wallet

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
db WalletDB

present, no coins will be available.

master HDPrivateKey | HDPublicKey <nullable>

Master HD key. If not present, it will be generated.

witness Boolean <nullable>

Whether to use witness programs.

accountIndex Number <nullable>

The BIP44 account index (default=0).

receiveDepth Number <nullable>

The index of the next receiving address.

changeDepth Number <nullable>

The index of the next change address.

type String <nullable>

Type of wallet (pubkeyhash, multisig) (default=pubkeyhash).

compressed Boolean <nullable>

Whether to use compressed public keys (default=true).

m Number <nullable>

m value for multisig.

n Number <nullable>

n value for multisig.

id String <nullable>

Wallet ID (used for storage) (default=account key "address").

Source:

Members

(private) _add

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

Source:

(private) _addSharedKey

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

Source:

_createAccount

Create an account without a lock.

Source:

(private) _createKey

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

Source:

(private) _decrypt

Decrypt the wallet permanently, without a lock.

Source:

(private) _encrypt

Encrypt the wallet permanently, without a lock.

Source:

(private) _fund

Fill a transaction with inputs without a lock.

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

_getAccount

Retrieve an account from the database without a lock.

Source:

(private) _importAddress

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

Source:

(private) _importKey

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

Source:

(private) _removeSharedKey

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

Source:

(private) _renameAccount

Rename account without a lock.

Source:

(private) _retoken

Generate a new token without a lock.

Source:

(private) _send

Build and send a transaction without a lock.

Source:

(private) _setLookahead

Increase lookahead for account (without a lock).

Source:

(private) _zap

Zap stale TXs from wallet without a lock.

Source:

abandon

Abandon transaction.

Source:

add

Add a transaction to the wallets TX history.

Source:

addSharedKey

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

Source:

createAccount

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

Source:

createKey

Create a new address (increments depth).

Source:

createTX

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.

Source:

decrypt

Decrypt the wallet permanently.

Source:

deriveInputs

Derive necessary addresses for signing a transaction.

Source:

destroy

Close the wallet, unregister with the database.

Source:

encrypt

Encrypt the wallet permanently.

Source:

ensureAccount

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

Source:

(private) ensureIndex

Resolve account index.

Source:

estimateSize

Input size estimator for max possible tx size.

Source:

fund

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

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

getAccount

Retrieve an account from the database.

Source:

getAccountByAddress

Get account by address.

Source:

getAccountHashes

Get all account address hashes.

Source:

getAccountIndex

Lookup the corresponding account name's index.

Source:

getAccountName

Lookup the corresponding account index's name.

Source:

getAccountPaths

Get all account paths.

Source:

getBalance

Get wallet balance.

Source:

getCoins

Get all available coins.

Source:

getHistory

Get all transactions in transaction history.

Source:

getInputPaths

Map input addresses to paths.

Source:

getKey

Retrieve a single keyring by address.

Source:

getLast

Get the last N transactions.

Source:

getOutputPaths

Map output addresses to paths.

Source:

getPath

Get path by address hash.

Source:

getPaths

Get all wallet paths.

Source:

getPending

Get all pending/unconfirmed transactions.

Source:

getPrivateKey

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

Source:

getRange

Get a range of transactions between two timestamps.

Source:

getRedeem

Get a redeem script or witness script by hash.

Source:

hasAccount

Test whether an account exists.

Source:

hasAddress

Test whether the wallet possesses an address.

Source:

hasPath

Test whether the wallet contains a path.

Source:

importAddress

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

Source:

importKey

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

Source:

increaseFee

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

Source:

init

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

Source:

lock

Lock the wallet, destroy decrypted key.

Source:

open

Open wallet (done after retrieval).

Source:

(private) readPath

Get path by address hash (without account name).

Source:

remove

Remove a wallet transaction.

Source:

removeSharedKey

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

Source:

rename

Rename the wallet.

Source:

renameAccount

Rename account.

Source:

resend

Resend pending wallet transactions.

Source:

retoken

Generate a new token.

Source:

send

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.

Source:

setLookahead

Increase lookahead for account.

Source:

setPassphrase

Change or set master key's passphrase.

Source:

sign

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

Source:

syncOutputDepth

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

Source:

template

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.

Source:

unconfirm

Unconfirm a wallet transcation.

Source:

zap

Zap stale TXs from wallet.

Source:

Methods

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

Instantiate wallet from options.

Parameters:
Name Type Description
db 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

(private) clear()

Clear batch.

Source:

commit() → {Promise}

Save batch.

Source:
Returns:
Type
Promise

createChange(acctnullable) → {Promise}

Create a new change address (increments receiveDepth).

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

createNested(acctnullable) → {Promise}

Create a new nested address (increments receiveDepth).

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

createReceive(acctnullable) → {Promise}

Create a new receiving address (increments receiveDepth).

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

(private) drop()

Drop batch.

Source:

(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:

getAccounts() → {Promise}

List account names and indexes from the db.

Source:
Returns:
  • Returns Array.
Type
Promise

getAddress(encnullable) → {Address|Base58Address}

Get current receive address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getAddressHashes(acctnullable) → {Promise}

Get all wallet address hashes.

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

getBlock(height) → {Promise}

Get a block from the wallet.

Parameters:
Name Type Description
height Number
Source:
Returns:
  • Returns BlockRecord.
Type
Promise

getBlocks() → {Promise}

List blocks for the wallet.

Source:
Returns:
  • Returns BlockRecord.
Type
Promise

getChange(encnullable) → {Address|Base58Address}

Get current change address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getCoin(hash, index) → {Promise}

Get a coin from the wallet.

Parameters:
Name Type Description
hash Hash
index Number
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

getDetails(hash) → {Promise}

Get transaction details.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Details.
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

getLocked() → {Array:.<Outpoint:>}

Return an array of all locked outpoints.

Source:
Returns:
Type
Array:.<Outpoint:>

getNested(encnullable) → {Address|Base58Address}

Get current nested address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getReceive(encnullable) → {Address|Base58Address}

Get current receive address.

Parameters:
Name Type Attributes Description
enc String <nullable>

"base58" or null.

Source:
Returns:
Type
Address | Base58Address

getSize() → {Number}

Calculate serialization size.

Source:
Returns:
Type
Number

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

inspect() → {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:

lockCoin(coin)

Lock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

save() → {Promise}

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

Source:
Returns:
Type
Promise

(private) start()

Start batch.

Source:

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: