Wallet

Wallet

Full Service BIP44 Multi-Coin Wallet supporting both sending and receiving payments




Constructor

new Wallet(seedopt, optionsopt) → {Wallet}

Create a new BIP44 wallet with the supplied settings

Examples

Create wallet with Random Mnemonic

let wallet = new Wallet()

Create wallet from BIP39 Mnemonic

let wallet = new Wallet("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")

Create wallet from BIP39 Entropy

let wallet = new Wallet('00000000000000000000000000000000')

Create wallet from Seed Hex

let wallet = new Wallet("5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4")

Create wallet from Seed Buffer

let wallet = new Wallet(Buffer.from("5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4", "hex"))
Parameters:
Name Type Attributes Description
seed string | Buffer <optional>

BIP39 Mnemonic, BIP39 Entropy, or Seed Hex/Buffer

options Object <optional>

Wallet settings

Properties
Name Type Attributes Default Description
discover boolean <optional>
false

Defines if the Wallet should "auto-discover" Coin Account chains or not

supportedCoins Array.<string> <optional>
['bitcoin', 'litecoin', 'flo']

An Array of coins that the Wallet should support

networks Array.<CoinInfo> <optional>

An array containing a custom coins network info

serializedData Object <optional>

A previous Wallet state to reload from

Source:
Example

Create wallet using Mnemonic

let wallet = new Wallet("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
Returns:
Type:
Wallet

Methods




addCoin(name, optionsopt)

Add a Coin to the Wallet

Parameters:
Name Type Attributes Description
name String

The coin "name" as defined in CoinInfo.name

options Object <optional>

Options you want passed to the coin being added

Source:



addTestnetCoins(boolopt)

Add default SUPPORTED testnet coins to wallet

Parameters:
Name Type Attributes Default Description
bool Boolean <optional>
true

if true, add testnet coins, is false, remove them

Source:



fromEntropy(entropy) → {Boolean}

Init Wallet from BIP39 Entropy

Parameters:
Name Type Description
entropy string

A BIP39 Entropy String

Source:
Example
let wallet = new Wallet();
wallet.fromEntropy('00000000000000000000000000000000')
Returns:

Returns if the operation was successful

Type:
Boolean



fromMnemonic(mnemonic) → {Boolean}

Init Wallet from BIP39 Mnemonic

Parameters:
Name Type Description
mnemonic string

A BIP39 Mnemonic String

Source:
Example
let wallet = new Wallet();
wallet.fromMnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
Returns:

Returns if the operation was successful

Type:
Boolean



fromSeed(seed) → {Boolean}

Init Wallet from a Seed

Parameters:
Name Type Description
seed string | Buffer
Source:
Example
let wallet = new Wallet();
wallet.fromSeed("example-seed");
Returns:

Returns if the operation was successful

Type:
Boolean



getCoin(coin) → {Coin}

Get a specific Coin

Parameters:
Name Type Description
coin string

The coin "name" as defined in CoinInfo.name

Source:
Example
let wallet = new Wallet();
let coin = wallet.getCoin("bitcoin")
Returns:

Returns the requested Coin

Type:
Coin



(async) getCoinBalances(optionsopt) → {Promise.<Object>}

Get Coin Balances

Parameters:
Name Type Attributes Description
options Object <optional>

The options for searching the Balance of coins

Properties
Name Type Attributes Default Description
coins Array <optional>
["bitcoin", "litecoin", "flo"]

An array of coin names you want to get the balances for. If no coins are given, an array of all available coins will be used.

discover Boolean <optional>
true

Should we attempt a new discovery, or just grab the available balances

testnet Boolean <optional>
true

Should we attempt to get balances for testnet coins as well (coins ending with 'Testnet')

Source:
Example
let wallet = new Wallet(...)
wallet.getCoinBalances(["bitcoin", "litecoin", "flo"])

//example return
{
     "flo": 2.16216,
     "bitcoin": "error fetching balance",
     "litecoin": 3.32211
}
Returns:

Returns a Promise that will resolve to an Object containing info about each coins balance, along with errors if there are any

Type:
Promise.<Object>



getCoins() → {Object.<number, Coin>}

Get all Coins running inside the Wallet

Source:
Example
let wallet = new Wallet();
let coins = wallet.getCoins();
// coins = {
//  "bitcoin": Coin,
//  "litecoin": Coin,
//  "flo": Coin
// }
Returns:

Object containing all coins

Type:
Object.<number, Coin>



getEntropy() → {string}

Get the Entropy value used to generate the BIP39 Mnemonic. Note that the Entropy will only be defined if we are creating a wallet from Entropy or a Mnemonic, not off of just the Seed Hex

Source:
Example
let wallet = new Wallet("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about");
let entropy = wallet.getEntropy()
// entropy = '00000000000000000000000000000000'
Returns:
Type:
string



(async) getExchangeRates(optionsopt) → {Promise.<Object>}

Calculate Exchange Rates for supported coins

Parameters:
Name Type Attributes Description
options Object <optional>

The options for getting the exchange rates

Properties
Name Type Attributes Default Description
coins Array <optional>
["bitcoin", "litecoin", "flo"]

An array of coin names you want to get the balances for. If no coins are given, an array of all available coins will be used.

fiat String <optional>
"usd"

The fiat type for which you wish to get the exchange rate for

Source:
Example
let wallet = new Wallet(...)
wallet.getExchangeRates(["flo", "bitcoin", "litecoin"], "usd")

//returns
{
     "flo": expect.any(Number) || "error",
     "bitcoin": expect.any(Number) || "error",
     "litecoin": expect.any(Number) || "error"
}
Returns:

Returns a Promise that will resolve to an Object containing info about each coins exchange rate, along with errors if there are any

Type:
Promise.<Object>



getExplorerUrls()

Get back the network explorer apis for supported coins

Source:



(async) getFiatBalances(optionsopt) → {Promise.<Object>}

Calculate Balance of coins after exchange rate conversion

Parameters:
Name Type Attributes Description
options Object <optional>

The options for getting the exchange rates

Properties
Name Type Attributes Default Description
coins Array <optional>
["bitcoin", "litecoin", "flo"]

An array of coin names you want to get the balances for. If no coins are given, an array of all available coins will be used.

fiat String <optional>
"usd"

The fiat type for which you wish to get the exchange rate for

discover Boolean <optional>
true

Should we attempt a new discovery, or just grab the available balances

testnet Boolean <optional>
true

should we include testnet coins?

Source:
Example
let wallet = new Wallet(...)
wallet.getFiatBalances(["flo", "bitcoin", "litecoin"], "usd")

//returns
{
     "flo": expect.any(Number) || "error",
     "bitcoin": expect.any(Number) || "error",
     "litecoin": expect.any(Number) || "error"
}
Returns:

Returns a Promise that will resolve to the fiat balances for each coin

Type:
Promise.<Object>



getMnemonic() → {string}

Get the BIP39 Mnemonic, if defined

Source:
Example
let wallet = new Wallet('00000000000000000000000000000000');
let mnemonic = wallet.getMnemonic()
// mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
Returns:
Type:
string



getNetworks()

Returns the network information for the coins available

Source:
Returns:

Array.




getSeed() → {string}

Get the Encoded Seed hex string

Source:
Example
let wallet = new Wallet('00000000000000000000000000000000');
let seedHex = wallet.getSeed()
// seedHex = '5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4'
Returns:

The hex string of the seed buffer

Type:
string



(async) sendPayment(options) → {Promise.<string>}

Parameters:
Name Type Description
options Object

Options about the payment you wish to send

Properties
Name Type Attributes Default Description
to OutputAddress | Array.<OutputAddress>

Define outputs for the Payment

coin string | Array.<string> <optional>

Define which coin you would like to send from

from string | Array.<string> <optional>
All Addresses in Coin

Define what public address(es) you wish to send from

fromAccounts number | Array.<number> <optional>
All Accounts in Coin

Define what Accounts on the Coin you wish to send from

discover Boolean <optional>
true

Should discovery happen before sending payment

floData string <optional>
""

Flo data to attach to the transaction

Source:
Returns:

Returns a promise that will resolve to the success TXID

Type:
Promise.<string>



setExplorerUrls(options)

Set the urls for the insight api explorers

Parameters:
Name Type Description
options
Properties
Name Type Description
flo string

flo api

floTestnet string

floTestnet api

bitcoin string

bitcoin api

bitcoinTestnet string

bitcoinTestnet api

litecoin string

litecoin api

litecoinTestnet string

litecoinTestnet api

Source:
Example
let options = {
    flo: 'myFloSiteApi.com/yadayada,
    bitcoin: 'myBitcoinApi.superApi/AyePeeEye',
    litecoin: 'superLightCoin.hero'
}
new Wallet(mnemonic, {discover: false}).setNetworkApi(options)