Utils

compileMemo

Compile memo.

Parameters

  • memo string The memo to be compiled.

Returns Buffer The compiled memo.

getFee

Get the transaction fee.

reference to https://github.com/Permissionless-Software-Foundation/bch-js/blob/acc0300a444059d612daec2564da743c11e27139/src/bitcoincash.js#L408

Parameters

  • inputs number The inputs count.
  • feeRate FeeRate The fee rate.
  • data Buffer The compiled memo (Optional). (optional, default null)
  • outputs number The outputs count.

Returns number The fee amount.

getBalance

Get the balances of an address.

Parameters

  • params AddressParams

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

bchNetwork

Get BCH network to be used with bitcore-lib.

Parameters

  • network Network

getPrefix

BCH new addresses strategy has no any prefixes. Any possible prefixes at the TX addresses will be stripped out with parseTransaction *

stripPrefix

Strips bchtest or bitcoincash prefix from address

Parameters

  • address Address

Returns Address The address with prefix removed

toLegacyAddress

Convert to Legacy Address.

Parameters

  • address Address

Returns Address Legacy address.

toCashAddress

Convert to Cash Address.

Parameters

  • address Address

Returns Address Cash address.

isCashAddress

Checks whether address is Cash Address

Parameters

  • address Address

Returns boolean Is cash address.

parseTransaction

Parse transaction.

Parameters

  • tx Transaction

Returns Tx Parsed transaction.*

toBCHAddressNetwork

Converts Network to bchaddr.Network

Parameters

  • network Network

Returns string bchaddr network

validateAddress

Validate the BCH address.

Parameters

  • address string
  • 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.haskoinUrl

scanUTXOs

Scan UTXOs from sochain.

Parameters

  • $0 Object
    • $0.haskoinUrl
    • $0.address
  • haskoinUrl string sochain Node URL.
  • 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.haskoinUrl

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

  • feeRate FeeRate
  • memo string (optional)
  • utxos UnspentOutput (optional) (optional, default [])

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.