Coin

Coin

Manage Accounts for a specific Coin




Constructor

new Coin(node, coin, optionsopt) → {Coin}

Create a new Coin object to interact with Accounts and Chains for that coin. This spawns a BIP44 compatible wallet.

Examples

Create a new Coin using a specified seed.

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)

Create a new Coin using a specified seed, don't auto discover.

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin, false)
Parameters:
Name Type Attributes Description
node string

BIP32 Node already derived to m/44'

coin CoinInfo

The CoinInfo containing network & version variables

options Object <optional>

The Options for spawning the Coin

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

Should the Coin auto-discover Accounts and Chains

serializedData Object <optional>

The Data to de-serialize from

Source:
Returns:
Type:
Coin

Methods




addAccount(accountNumberopt, discoveropt) → {Account}

Add the Account at the specified number, if it already exists, it returns the Account. If the Account does not exist, it will create it and then return it.

Parameters:
Name Type Attributes Default Description
accountNumber number <optional>
0
discover Boolean <optional>
discover Set in Coin Constructor

Should the Account start auto-discovery.

Source:
Example
import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let account = bitcoin.addAccount(1)
Returns:
Type:
Account



(async) discoverAccounts() → {Promise.<Array.<Account>>}

Discover all Accounts for the Coin

Source:
Example
import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin, false)
bitcoin.discoverAccounts().then((accounts) => {
  console.log(accounts.length)
})
Returns:

Returns a Promise that will resolve to an Array of Accounts once complete

Type:
Promise.<Array.<Account>>



getAccount(accountNumberopt) → {Account}

Get the Account at the specified number

Parameters:
Name Type Attributes Default Description
accountNumber number <optional>
0
Source:
Examples

Get Default Account

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let account = bitcoin.getAccount()

Get Account #1

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let account = bitcoin.getAccount(1)
Returns:
Type:
Account



getAccounts() → {Object.<number, Account>}

Get all Accounts on the Coin

Source:
Example
import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let accounts = bitcoin.getAccounts()
// accounts = {
//   0: Account,
//   1: Account
// }
Returns:

Returns a JSON object with accounts

Type:
Object.<number, Account>



getAddress(accountNumberopt, chainNumberopt, addressIndexopt) → {Address}

Get a specific Address

Parameters:
Name Type Attributes Default Description
accountNumber number <optional>
0

Number of the account you wish to get the Address from

chainNumber number <optional>
0

Number of the Chain you wish to get the Address from

addressIndex number <optional>
0

Index of the Address you wish to get

Source:
Returns:
Type:
Address



(async) getBalance(optionsopt) → {Promise.<number>}

Get the balance for the entire coin, or a specific address/array of addresses

Parameters:
Name Type Attributes Description
options Object <optional>

Specific options defining what balance to get back

Properties
Name Type Attributes Default Description
discover Boolean <optional>
true

Should the Coin discover Accounts

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

Get Balance for defined Accounts

addresses string | Array.<string> <optional>
All Addresses in each Account in Coin

Get Balance for defined Addresses

Source:
Example

Get Balance for entire Coin

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
bitcoin.getBalance().then((balance) => {
   console.log(balance)
})
Returns:

A Promise that will resolve to the balance of the entire Coin

Type:
Promise.<number>



getCoinInfo() → {CoinInfo}

Get the CoinInfo for the Coin

Source:
Example
import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let coinInfo = bitcoin.getCoinInfo()
// coinInfo = Networks.bitcoin
Returns:
Type:
CoinInfo



getExtendedPrivateKey() → {string}

Get the Extended Private Key for the root path. This is derived at m/44'/coinType'

Source:
Example

Get the Extended Private Key for the entire Coin

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let extPrivateKey = bitcoin.getExtendedPrivateKey()
// extPrivateKey = xprv9x8MQtHNRrGgrnWPkUxjUC57DWKgkjobwAYUFedxVa2FAA5qaQuGqLkJnVcszqomTar51PCR8JiKnGGgzK9eJKGjbpUirKPVHxH2PU2Rc93
Returns:

The Extended Private Key

Type:
string



getExtendedPublicKey() → {string}

Get the Neutered Extended Public Key for the root path. This is derived at m/44'/coinType'

Source:
Example

Get the Extended Private Key for the entire Coin

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let extPublicKey = bitcoin.getExtendedPrivateKey()
// extPublicKey = xpub6B7hpPpGGDpz5GarrWVjqL1qmYABACXTJPU5433a3uZE2xQz7xDXP94ndkjrxogjordTDSDaHY4i5G4HqRH6E9FJZk2F4ED4cbnprW2Vm9v
Returns:

The Extended Public Key

Type:
string



getMainAddress(accountNumberopt) → {Address}

Get the Main Address for a specific Account number. This is the Address at index 0 on the External Chain of the Account.

Parameters:
Name Type Attributes Default Description
accountNumber number <optional>
0

Number of the Account you wish to get

Source:
Examples

Get Main Address for Coin

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let mainAddress = bitcoin.getMainAddress()

Get Main Address for Account #1 on Coin

import { Coin, Networks } from '@oipwg/hdmw'

let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let mainAddress = bitcoin.getMainAddress(1)
Returns:
Type:
Address



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

Send a Payment to specified Addresses and Amounts

Parameters:
Name Type Description
options Object

the options for the specific transaction being sent

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

Define outputs for the Payment

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