Constructor
new Address(address, coin, discoveropt) → {Address}
Create a new Address based on either a bip32 node, WIF Private Key, or Public Address
Examples
Create Address from bip32
import * as bip32 from 'bip32';
import { Address, Networks } from '@oipwg/hdmw';
let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo);
Create Address from WIF
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("RAtKUeXYMEHEFkhbJuXGMEQZsqgHosnP2BLVaLWMRswWrcCNbZk5", Networks.flo);
Create Address from Base58 Public Address
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo);
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
address |
bip32 | string |
The Public Address, Private Key (WIF), or bip32 Node that the Address is for. |
||
coin |
CoinInfo |
CoinInfo for the specific Address |
||
discover |
boolean | AddressState |
<optional> |
false |
Either a |
- Source:
Returns:
- Type:
- Address
Methods
addSpentTransaction(txid)
Add a TXID to the local Spent Transactions of the Address to prevent a specific output from being doublespent.
Parameters:
Name | Type | Description |
---|---|---|
txid |
string |
The TXID of the spent output that we should remove |
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
address.addSpentTransaction("7687e361f00998f96b29938bf5b7d9003a15ec182c13b6ddbd5adc0f993cbf9c")
deserialize(state) → {Address}
Hydrate an Address from the serialized JSON, or update the state
Parameters:
Name | Type | Description |
---|---|---|
state |
AddressState |
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
address.deserialize({
addrStr: 'F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp',
balanceSat: 123,
totalReceivedSat: 234,
unconfirmedBalanceSat: 345,
transactions: ['abcde'],
spentTransactions: ['bcdef'],
lastUpdated: 456
})
let balance = address.getBalance()
// balance = 0.00000123
Returns:
- Type:
- Address
getBalance() → {number}
Get the Balance (in whole coins) for the Address
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
let balance = address.getBalance();
// balance = 0
Returns:
- Type:
- number
getECPair() → {ECPair}
Get the internal ECPair. This is used when you need to Sign Transactions, or to access the raw public/private Buffers. Please note that if you create the Address from a Public Key, you will not get back an ECPair, since we need access to the Private Key in order to create/access the ECPair. When Address is created using a bip32 node or a Private Key (WIF) the ECPair will exist.
- Source:
Example
import * as bip32 from 'bip32';
import { Address, Networks } from '@oipwg/hdmw';
let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo);
let ecpair = address.getECPair();
Returns:
- Type:
- ECPair
getPrivateAddress() → {string}
Get the Base58 sharable Private Address (WIF)
- Source:
Example
import * as bip32 from 'bip32';
import { Address, Networks } from '@oipwg/hdmw';
let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo);
let wif = address.getPrivateAddress();
// wif = RAtKUeXYMEHEFkhbJuXGMEQZsqgHosnP2BLVaLWMRswWrcCNbZk5
Returns:
- Type:
- string
getPublicAddress() → {string}
Get the Base58 sharable Public Address
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("RAtKUeXYMEHEFkhbJuXGMEQZsqgHosnP2BLVaLWMRswWrcCNbZk5", Networks.flo);
let pubAddr = address.getPublicAddress();
// pubAddr = F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp
Returns:
- Type:
- string
getTotalReceived() → {number}
Get the Total Received balance (in whole coins) for the Address
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
let totReceived = address.getTotalReceived();
// totReceived = 0
Returns:
- Type:
- number
getTotalSent() → {number}
Get the Total Sent balance (in whole coins) for the Address
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
let totSent = address.getTotalSent();
// totSent = 0
Returns:
- Type:
- number
getUnconfirmedBalance() → {number}
Get the Unconfirmed Balance (in whole coins) for the Address
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
let uBal = address.getUnconfirmedBalance();
// uBal = 0
Returns:
- Type:
- number
getUnspent() → {Promise.<Array.<utxo>>}
Get the unspent transaction outputs for the Address
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
address.getUnspent().then((utxos) => {
console.log(utxos);
})
Returns:
Returns a Promise that resolves to an Array of utxos.
- Type:
- Promise.<Array.<utxo>>
removeSpent(unspentTransactions) → {Array.<utxo>}
Remove the already spent outputs from the array we are given.
Parameters:
Name | Type | Description |
---|---|---|
unspentTransactions |
Array.<utxo> |
An Array containing utxos to sort through |
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
address.getUnspent().then((utxos) => {
let unspentUtxos = address.removeSpent(utxos)
console.log(unspentUtxos)
})
Returns:
- Type:
- Array.<utxo>
serialize() → {AddressState}
Get a serialized version of the Address (dried out JSON)
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo, false);
let addressState = address.serialize()
// addressState = {
// addrStr: 'F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp',
// balanceSat: 0,
// totalReceivedSat: 0,
// unconfirmedBalanceSat: 0,
// transactions: [],
// spentTransactions: [],
// lastUpdated: 0
// }
Returns:
- Type:
- AddressState
signMessage(message) → {String}
Get the signature of a specific message that can be verified by others
Parameters:
Name | Type | Description |
---|---|---|
message |
String |
The message you wish to get the signature for |
- Source:
Returns:
Returns the base64 string of the created Signature
- Type:
- String
(async) updateState() → {Promise.<Address>}
Get the latest State for this address from the Blockchain Explorer
- Source:
Example
import { Address, Networks } from '@oipwg/hdmw';
let address = new Address("F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp", Networks.flo);
address.updateState().then((addr) => {
console.log(addr.getTotalReceived())
})
Returns:
Returns a Promise that will resolve to the Address
- Type:
- Promise.<Address>
verifySignature(message, signature) → {Boolean}
Verify the signature of a given message
Parameters:
Name | Type | Description |
---|---|---|
message |
String |
The message you want to verify |
signature |
String |
The signature of the message |
- Source:
Returns:
Returns either true
or false
depending on if the signature and message match
- Type:
- Boolean