Constructor
new Account(accountMaster, coin, optionsopt) → {Account}
Create a new Account to manage Chains and Addresses for based on a BIP32 Node
Examples
Create a Bitcoin Account
import { Account, Networks } from '@oipwg/hdmw';
let accountMaster = bip32.fromBase58("xprv9xpXFhFpqdQK3TmytPBqXtGSwS3DLjojFhTGht8gwAAii8py5X6pxeBnQ6ehJiyJ6nDjWGJfZ95WxByFXVkDxHXrqu53WCRGypk2ttuqncb")
let account = new Account(accountMaster, Networks.bitcoin);
Create a Flo Account
import { Account, Networks } from '@oipwg/hdmw';
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo);
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
accountMaster |
bip32 |
The BIP32 Node to derive Chains and Addresses from. |
||||||||||||||||
coin |
CoinInfo |
The CoinInfo for the Account |
||||||||||||||||
options |
Object |
<optional> |
The Options of the Account Properties
|
- Source:
Returns:
- Type:
- Account
Methods
(async) discoverChain(chainNumber) → {Promise.<Account>}
Discover Used and Unused addresses for a specified Chain number
Parameters:
Name | Type | Description |
---|---|---|
chainNumber |
number |
The number of the chain you wish to discover |
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
account.discoverChain(0).then((acc) => {
console.log(acc.getChain(0).addresses)
})
Returns:
- A Promise that once finished will resolve to the Account (now with discovery done)
- Type:
- Promise.<Account>
(async) discoverChains() → {Promise.<Account>}
Discover all Chains
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
account.discoverChains().then((acc) => {
console.log(acc.getChain(0).addresses)
console.log(acc.getChain(1).addresses)
})
Returns:
- A Promise that once finished will resolve to the Account (now with discovery done)
- Type:
- Promise.<Account>
getAddress(chainNumberopt, addressNumberopt) → {Address}
Get the Address for a specified Chain and Index on the Chain.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
chainNumber |
number |
<optional> |
0 |
Number of the specific chain you want to get the Address from |
addressNumber |
number |
<optional> |
0 |
Index of the Address on the specified chain |
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let address = account.getAddress(0, 10)
// address.getPublicAddress() = F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp
Returns:
- Type:
- Address
getAddresses(chainNumberopt) → {Array.<Address>}
Get all derived Addresses for the entire Account, or just for a specific Chain.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
chainNumber |
number |
<optional> |
Number of the specific chain you want to get the Addresses from |
- Source:
Examples
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let addresses = account.getAddresses()
// addresses = [Address, Address, Address]
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let addresses = account.getAddresses(0)
// addresses = [Address, Address, Address]
Returns:
- Type:
- Array.<Address>
(async) getBalance(optionsopt) → {Promise.<number>}
Get the Balance for the entire Account
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Specific options defining what balance to get back Properties
|
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
account.getBalance({ discover: true }).then((balance) => {
console.log(balance);
})
Returns:
- Returns a Promise that will resolve to the total balance.
- Type:
- Promise.<number>
getChain(chainNumber) → {bip32utils.Chain}
Get the specified Chain number
Parameters:
Name | Type | Description |
---|---|---|
chainNumber |
number |
The number of the chain you are requesting |
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let chain = account.getChain(0)
Returns:
- Type:
- bip32utils.Chain
getExtendedPrivateKey() → {string}
Get the Extended Private Key for the Account
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let extPrivateKey = account.getExtendedPrivateKey()
// extPrivateKey = Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC
Returns:
- Type:
- string
getExtendedPublicKey() → {string}
Get the Extended Public Key for the Account
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let extPublicKey = account.getExtendedPublicKey()
// extPublicKey = Fpub1BPo8vEQqDkoDQmDqcJ8WFHD331AMpd7VU7atCJsix8xbHwN6K9wfDLjZKnW9fUw5uJg8UJMLhQ5W7gTxv6DbkfPoeJbBpMaUHrULxzVnSy
Returns:
- Type:
- string
getMainAddress(chainNumberopt, mainAddressNumberopt) → {Address}
Get the Main Address for a specified Chain and Index on the Chain.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
chainNumber |
number |
<optional> |
0 |
Number of the specific chain you want to get the Main Address for |
mainAddressNumber |
number |
<optional> |
0 |
Index of the Main Address on the specified chain |
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let address = account.getMainAddress()
// address.getPublicAddress() = FPznv9i9iHX5vt4VMbH9x2LgUcrjtSn4cW
Returns:
- Type:
- Address
getNextChainAddress(chainNumberopt) → {Address}
Get the Next Chain Address for a specified chain
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
chainNumber |
number |
<optional> |
0 |
The specific chain that you want to get the next address from |
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let address = account.getNextChainAddress(1)
Returns:
- Type:
- Address
getNextChangeAddress() → {Address}
Get the Next Change Address from the "Internal" chain
- Source:
Example
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let address = account.getNextChangeAddress()
Returns:
- Type:
- Address
getUsedAddresses(chainNumberopt) → {Array.<Address>}
Get all Used Addresses (addresses that have received at least 1 tx) for the entire Account, or just for a specific Chain.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
chainNumber |
number |
<optional> |
Number of the specific chain you want to get the Addresses from |
- Source:
Examples
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let addresses = account.getUsedAddresses()
// addresses = [Address, Address, Address]
import * as bip32 from 'bip32'
import { Account, Networks } from '@oipwg/hdmw'
let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", Networks.flo.network)
let account = new Account(accountMaster, Networks.flo, false);
let addresses = account.getUsedAddresses(0)
// addresses = [Address, Address, Address]
Returns:
- Type:
- Array.<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
|
- Source:
Returns:
- Returns a promise that will resolve to the success TXID
- Type:
- Promise.<string>