Constructor
new ExplorerWallet()
Example
import {OIP} from 'js-oip'
let wif = "cRVa9rNx5N1YKBw8PhavegJPFCiYCfC4n8cYmdc3X1Y6TyFZGG4B"
let oip = new OIP(wif, "testnet")
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options.wif |
string |
private key in Wallet Import Format (WIF) see: https://en.bitcoin.it/wiki/Wallet_import_format |
||
options.network |
string |
<optional> |
"mainnet" |
Use "testnet" for testnet |
- Source:
Methods
addSpentTransaction(txid) → {void}
Add a spent transaction to local memory
Parameters:
Name | Type | Description |
---|---|---|
txid |
TXID |
transaction id |
Example
let oip = new OIP(wif, "testnet")
let output = {
address: "oNAydz5TjkhdP3RPuu3nEirYQf49Jrzm4S",
value: Math.floor(0.001 * floTestnet.satPerCoin)
}
let txid = await oip.createAndSendFloTx(output, "sending floData to testnet")
oip.addSpentTransaction(txid)
let spentTxs = oip.getSpentTransactions()
spentTxs === [txid] //true
Returns:
- Type:
- void
(async) broadcastRawHex(hex) → {Promise.<string>}
Broadcast raw transaction hex to the FLO chain
Parameters:
Name | Type | Description |
---|---|---|
hex |
Returns:
txid - Returns a transaction id
- Type:
- Promise.<string>
(async) buildInputsAndOutputs(floDataopt, outputsopt) → {Promise.<Object>}
Builds the inputs and outputs to form a valid transaction hex for the FLO Chain
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
floData |
string |
<optional> |
"" |
defaults to an empty string |
outputs |
object | Array.<object> |
<optional> |
Output or an array of Outputs to send to |
Examples
//basic
let oip = new OIP(wif, "testnet")
let selected = await oip.buildInputsAndOutputs("floData") //returns selected inputs, outputs, and fee
//with custom output and object destructuring
let oip = new OIP(wif, "testnet")
let output = {
address: "ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4",
value: 1e8 //in satoshis
}
let {inputs, outputs, fee} = await oip.buildInputsAndOutputs("floData", output)
Returns:
Returns the selected inputs, outputs, and fee to use for the transaction hex
- Type:
- Promise.<Object>
(async) buildTXHex(floDataopt, outputopt) → {Promise.<string>}
Build a valid FLO Raw TX Hex containing floData
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
floData |
String |
<optional> |
"" |
String data to send with tx. Defaults to an empty string |
output |
object | Array.<object> |
<optional> |
Custom output object |
Example
//if no output is designed, it will send 0.0001 * 1e8 FLO to yourself
let output = {
address: "ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4",
value: 1e8 //satoshis
}
let op = new OIP(wif, "testnet")
let hex = await op.buildTXHex("floData", output)
Returns:
hex - Returns raw transaction hex
- Type:
- Promise.<string>
createManualUtxos() → {Array.<utxo>}
Manually create Unspent Transaction Outputs from previous known transactions. Loops through spent transaction IDs in localStorage and created txs to find outputs to use.
Returns:
- Type:
- Array.<utxo>
deleteHistory()
WARNING!!! Deleting history may cause publishing to temporary fail as it might attempt to use spent transactions. Deletes the publisher history from localStorage
deserialize()
Imports publisher history from localStorage
Example
let oip = new OIP(wif)
oip.deserialize() //sets this.spentTransactions and this.history from localStorage memory variables
getCoinInfo() → {CoinInfo}
Returns information about the current coin (either FLO or FLO_Testnet)
Returns:
- Type:
- CoinInfo
getECPair() → {object}
Returns the ECPair (private/public key pair) generated from the given wif
Returns:
- Type:
- object
getNetwork() → {CoinNetwork}
Returns coin network information needed for address generation
Returns:
- Type:
- CoinNetwork
getPubAddress() → {string}
Returns the pay-to-pubkey-hash address generated from the given wif
Returns:
- Type:
- string
getSpentTransactions() → {Array.<TXID>}
Returns an array of spent transaction ids
Example
let oip = new OIP(wif, "testnet")
oip.addSpentTransaction(txid)
let txids = oip.getSpentTransactions()
txids = [txid] //true
Returns:
- Type:
- Array.<TXID>
getTxHistory() → {Object}
Returns tx history variables
Example
let oip = new OIP(wif)
oip.getTxHistory()
//returns
// {
// history: this.history,
// spentTransactions: this.spentTransactions
// }
Returns:
- Type:
- Object
(async) getUTXO() → {Promise.<Array.<utxo>>}
Get Unspent Transaction Outputs for the given keypair
Example
const wif = 'cRVa9rNx5N1YKBw8PhavegJPFCiYCfC4n8cYmdc3X1Y6TyFZGG4B'
let oip = new OIP(wif, "testnet")
let utxos = await oip.getUTXO()
for (let tx of utxos) {
console.log(tx)
// [ { address: 'ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4',
// txid: '40bf49a02731b04b71951d2e7782b93bd30678c5f5608f0cfe9cdaed6d392903',
// vout: 1,
// scriptPubKey: '76a914f93aef4f4ef998b7ae44bd5bc8f6627b79cdc07588ac',
// amount: 659.9999325,
// satoshis: 65999993250,
// height: 295680,
// confirmations: 5706
// } ]
}
Returns:
- Type:
- Promise.<Array.<utxo>>
removeSpent(unspentTransactions) → {Array.<utxo>}
Removes already spent transactions (that are kept in local memory)
Parameters:
Name | Type | Description |
---|---|---|
unspentTransactions |
Array.<utxo> |
An array of utxos |
Example
//shouldn't ever have to write this. Use `OIP.getUTXO()` instead
let oip = new OIP(wif, 'testnet')
let utxo
try {
utxo = await oip.explorer.getAddressUtxo(pubAddr)
} catch (err) {
throw new Error(`${err}`)
}
return oip.removeSpent(utxo)
Returns:
- Type:
- Array.<utxo>
save(txid, hex)
Saves a transaction to localStorage and memory
Parameters:
Name | Type | Description |
---|---|---|
txid |
string | |
hex |
string |
(async) sendDataToChain(data) → {Promise.<string>}
Send string data to the FLO Chain
Parameters:
Name | Type | Description |
---|---|---|
data |
string |
String data. Must be below or equal to 1040 characters |
Returns:
txid - Returns the id of the transaction that contains the published data
- Type:
- Promise.<string>
(async) sendTx(outputs, floData) → {Promise.<TXID>}
Create and send a FLO tx with a custom output
Parameters:
Name | Type | Description |
---|---|---|
outputs |
object | Array.<object> | |
floData |
string |
Example
let oip = new OIP(wif, "testnet")
let output = {
address: "oNAydz5TjkhdP3RPuu3nEirYQf49Jrzm4S",
value: 100000000
}
let txid = await oip.createAndSendFloTx(output, "to testnet")
Returns:
- Type:
- Promise.<TXID>
serialize()
Stores important local variables to localStorage such as spent transactions and publish history