Constructor
new OIPPublisher(wif, networkopt)
Create a new Publisher. Use in conjuction with the Artifact class to publish valid OIP Records or just post random data onto the chain
Example
Instantiate and use a Publisher
let wif = "cRVa9rNx5N1YKBw8PhavegJPFCiYCfC4n8cYmdc3X1Y6TyFZGG4B"
network = "testnet" //defaults to mainnet
let publisher = new OIPPublisher(wif, network)
//Publish arbitrary data
publisher.publishData('Hello, Testnet)').then(txid => txid).catch(err => err)
//Publish data when using the OIP Spec
let artifact = new Artifact()
publisher.publish(artifact.toString()).then(response => response).catch(err => err)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
wif |
string |
private key in Wallet Import Format (WIF) |
||
network |
string |
<optional> |
"mainnet" |
Use "testnet" for testnet |
Methods
addSpentTransaction(txid) → {void}
Add a spent transaction to local memory
Parameters:
Name | Type | Description |
---|---|---|
txid |
string |
transaction id |
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, output) → {Promise.<Object>}
Builds the inputs and outputs to form a valid transaction hex
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
floData |
string |
<optional> |
"" |
defaults to an empty string |
output |
Object |
custom output object |
Returns:
selected - Returns the selected inputs to use for the transaction hex
- Type:
- Promise.<Object>
(async) buildTXHex(floDataopt, output) → {Promise.<string>}
Build a valid FLO Raw TX Hex containing floData
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
floData |
string |
<optional> |
"" |
defaults to an empty string |
output |
Object |
custom output object |
Returns:
hex - Returns raw transaction hex
- Type:
- Promise.<string>
deleteHistory()
Deletes the publisher history from localStorage
deserialize()
Imports publisher history from localStorage
getHistory() → {Object}
Returns publisher history variables
Returns:
- Type:
- Object
(async) getUTXO() → {Promise.<Array.<Object>>}
Get Unspent Transaction Outputs for the given keypair
Returns:
utxo - Returns unspent transaction outputs
- Type:
- Promise.<Array.<Object>>
(async) publish(data) → {Promise.<(string|Array.<string>)>}
Publish OIP Objects to the FLO Chain (will format it as best it can to the protocol spec)
Parameters:
Name | Type | Description |
---|---|---|
data |
string |
the string data you wish to publish !!Make sure to stringify your objects/classes |
Returns:
txid - the txid(s) of the broadcasted messages
- Type:
- Promise.<(string|Array.<string>)>
(async) publishData(data) → {Promise.<string>}
Publish arbitrary 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) publishMultiparts(data) → {Promise.<Array.<String>>}
Publish data that exceeds the maximum floData length in multiple parts
Parameters:
Name | Type | Description |
---|---|---|
data |
string |
The data you wish to publish |
Returns:
txids - An array of transaction IDs
- Type:
- Promise.<Array.<String>>
removeSpent(unspentTransactions) → {Array.<Object>}
Removes already spent transactions (that are kept in local memory)
Parameters:
Name | Type | Description |
---|---|---|
unspentTransactions |
Returns:
- Type:
- Array.<Object>
save(txid, hex)
Saves a transaction to localStorage and memory
Parameters:
Name | Type | Description |
---|---|---|
txid |
string | |
hex |
string |
serialize()
Stores important local variables to localStorage such as spent transactions and publish history