TransactionBuilder

TransactionBuilder

Build & Send Transactions out to the network Easily using Addresses!




Constructor

new TransactionBuilder(coin, optionsopt, accountopt) → {TransactionBuilder}

Create a new TransactionBuilder

Example
import * as bip32 from 'bip32'
import { Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo, false)

let builder = new TransactionBuilder(Networks.flo, {
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001},
  floData: "Testing oip-hdmw!"
})
Parameters:
Name Type Attributes Description
coin CoinInfo

CoinInfo for this specific Network you want to send the Transaction on.

options Object <optional>
Properties
Name Type Attributes Default Description
from Address | Array.<Address>

The Address(es) to send from.

to OutputAddress | Array.<OutputAddress>

The amounts & Address(es) to send to.

floData string <optional>
""

The FloData to be added to the Transaction

account Account <optional>

An Account to get a Change Address from if needed, if undefined, change will be sent to first from Address.

Source:
Returns:
Type:
TransactionBuilder

Methods




addFrom(address)

Add an Address to send from

Parameters:
Name Type Description
address Address

Address to add to the From Addresses

Source:
Example
import * as bip32 from 'bip32'
import { Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo, false)

let builder = new TransactionBuilder(Networks.flo)
builder.addFrom(address);



addTo(address, amount)

Add an Address and Amount to send to

Parameters:
Name Type Description
address string

Base58 Public Address to send To

amount number

Amount to Send (in whole coin)

Source:
Example
import * as bip32 from 'bip32'
import { TransactionBuilder, Networks } from '@oipwg/hdmw'

let builder = new TransactionBuilder(Networks.flo)
builder.addTo("FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu", 0.001);



(async) buildInputsAndOutputs(manualUtxosopt) → {SelectedInputOutput}

Get calculated Inputs and Outputs (and Fee) for From and To Addresses

Parameters:
Name Type Attributes Description
manualUtxos Array.<utxo> <optional>

Pass in utxos for the function to use. If not passed, it will call the function getUnspents()

Source:
Example
import * as bip32 from 'bip32'
import { Account, Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", networks.flo.network)
let account = new Account(accountMaster, networks.flo, false);

let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo, false)

let builder = new TransactionBuilder(Networks.flo, {
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001}
}, account)

builder.buildInputsAndOutputs().then((calculated) => {
  console.log(calculated.inputs)
  console.log(calculated.outputs)
  console.log(calculated.fee)
})
Returns:
Type:
SelectedInputOutput



(async) buildTX(manualSelectedopt) → {Promise.<string>}

Build the Transaction hex for the From and To addresses

Parameters:
Name Type Attributes Description
manualSelected SelectedInputOutput <optional>

Inputs and Outputs to use. If not passed, the function buildInputsAndOutputs() is run.

Source:
Example
import * as bip32 from 'bip32'
import { Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", networks.flo.network)
let account = new Account(accountMaster, networks.flo, false);

// F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp
let addressNode = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", networks.flo.network)
let address = new Address(addressNode, networks.flo, false);

let builder = new TransactionBuilder(networks.flo, {
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001},
  floData: "Testing oip-hdmw!"
}, account)

builder.buildTX().then((hex) => {
  console.log(hex)
})
Returns:

Returns a Promise that resolves to the calculated Transaction Hex

Type:
Promise.<string>



(async) discoverChange() → {Promise}

Discover the used change addresses if we were passed an Account to discover from.

Source:
Example
import * as bip32 from 'bip32'
import { Account, Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", networks.flo.network)
let account = new Account(accountMaster, networks.flo, false);

let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo, false)

let builder = new TransactionBuilder(Networks.flo, {
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001}
}, account)

builder.discoverChange().then(() => {
  console.log("Done Discovering Change!")
})
Returns:
Type:
Promise



(async) getUnspents() → {Promise.<Array.<utxo>>}

Get the Unspent Transaction Outputs for all the From addresses specified.

Source:
Example
import * as bip32 from 'bip32'
import { Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo, false)

let builder = new TransactionBuilder(Networks.flo, {
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001}
})

builder.getUnspents().then((utxos) => {
  console.log(utxos)
})
Returns:

Returns a Promise that will resolve to an Array of unspent utxos

Type:
Promise.<Array.<utxo>>



parseOptions(options)

Load From & To addresses

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
from Address | Array.<Address>

The Address(es) to send from.

to OutputAddress | Array.<OutputAddress>

The amounts & Address(es) to send to.

floData string <optional>
""

The FloData to be added to the Transaction

Source:
Example
import * as bip32 from 'bip32'
import { Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let node = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", Networks.flo.network)
let address = new Address(node, Networks.flo, false)

let builder = new TransactionBuilder(Networks.flo)

builder.parseOptions({
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001},
  floData: "Testing oip-hdmw!"
})



(async) sendTX(manualHexopt) → {Promise.<string>}

Build & Send the Transaction that we have been forming

Parameters:
Name Type Attributes Description
manualHex String <optional>

The hex you wish to send the tx for. If not used, the hex is grabbed from buildTX().

Source:
Example
import * as bip32 from 'bip32'
import { Address, TransactionBuilder, Networks } from '@oipwg/hdmw'

let accountMaster = bip32.fromBase58("Fprv4xQSjQhWzrCVzvgkjam897LUV1AfxMuG8FBz5ouGAcbyiVcDYmqh7R2Fi22wjA56GQdmoU1AzfxsEmVnc5RfjGrWmAiqvfzmj4cCL3fJiiC", networks.flo.network)
let account = new Account(accountMaster, networks.flo, false);

// F8P6nUvDfcHikqdUnoQaGPBVxoMcUSpGDp
let addressNode = bip32.fromBase58("Fprv52CvMcVNkt3jU7MjybjTNie1Bqm7T66KBueSVFW74hXH43sXMAUdmk73TENACSHhHbwm7ZnHiaW3DxtkwhsbtpNjsh4EpnFVjZVJS7oxNqw", networks.flo.network)
let address = new Address(addressNode, networks.flo, false);

let builder = new TransactionBuilder(networks.flo, {
  from: address,
  to: {"FHQvhgDut1rn1nvQRZ3z9QgMEVMavRo2Tu": 0.00001},
  floData: "Testing oip-hdmw!"
}, account)

builder.sendTX().then((txid) => {
  console.log(txid)
})
Returns:

Returns a promise that will resolve to the success TXID

Type:
Promise.<string>