Utils

compileMemo

Compile memo.

Parameters

  • memo string The memo to be compiled.

Returns Buffer The compiled memo.

getFee

Get the transaction fee.

Parameters

  • inputs Array<UTXO> The UTXOs.
  • feeRate FeeRate The fee rate.
  • data Buffer The compiled memo (Optional). (optional, default null)

Returns number The fee amount.

arrayAverage

Get the average value of an array.

Parameters

Returns number The average value.

btcNetwork

Get Bitcoin network to be used with bitcoinjs.

Parameters

  • network Network

Returns Bitcoin.Network The BTC network.

getBalance

Get the balances of an address.

Parameters

  • $0 Object
    • $0.params
    • $0.haskoinUrl
    • $0.confirmedOnly
  • sochainUrl string sochain Node URL.
  • network Network
  • address Address

Returns Array<Balance> The balances of the given address.

validateAddress

Validate the BTC address.

Parameters

  • address Address
  • network Network

Returns boolean true or false.

getTxHex

Helper to get hex of Tx

It will try to get it from cache before requesting it from Sochain

Parameters

  • $0 Object
    • $0.txHash
    • $0.sochainUrl
    • $0.network

scanUTXOs

Scan UTXOs from sochain.

Parameters

  • $0 Object
    • $0.sochainUrl
    • $0.haskoinUrl
    • $0.network
    • $0.address
    • $0.confirmedOnly (optional, default true)
    • $0.withTxHex (optional, default false)
  • sochainUrl string sochain Node URL.
  • network Network
  • address Address

Returns Array<UTXO> The UTXOs of the given address.

buildTx

Build transcation.

Parameters

  • params BuildParams The transaction build options.
    • params.amount
    • params.recipient
    • params.memo
    • params.feeRate
    • params.sender
    • params.network
    • params.sochainUrl
    • params.haskoinUrl
    • params.spendPendingUTXO (optional, default false)
    • params.withTxHex (optional, default false)

Returns Transaction

broadcastTx

Broadcast the transaction.

Parameters

  • params BroadcastTxParams The transaction broadcast options.
    • params.haskoinUrl
    • params.txHex

Returns TxHash The transaction hash.

calcFee

Calculate fees based on fee rate and memo.

Parameters

Returns BaseAmount The calculated fees based on fee rate and the memo.

getDefaultFeesWithRates

Get the default fees with rates.

Returns FeesWithRates The default fees and rates.

getDefaultFees

Get the default fees.

Returns Fees The default fees.

getPrefix

Get address prefix based on the network.

Parameters

  • network Network

Returns string The address prefix based on the network.*