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
|
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. |
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
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 |
Examples
import { Coin, Networks } from '@oipwg/hdmw'
let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let account = bitcoin.getAccount()
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
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 |
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
|
Example
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
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'
Example
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'
Example
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 |
Examples
import { Coin, Networks } from '@oipwg/hdmw'
let bitcoin = new Coin('00000000000000000000000000000000', Networks.bitcoin)
let mainAddress = bitcoin.getMainAddress()
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
|
Returns:
- Returns a promise that will resolve to the success TXID
- Type:
- Promise.<string>