Module: outputs

This module provides functions for validating transaction output and amounts.

Source:

Members

(inner, constant) DUST_LIMIT_SATS :BigNumber

Lowest acceptable output amount in Satoshis.

Type:
  • BigNumber
Default Value:
  • 546 Satoshis
Source:

Methods

(static) validateOutput(network, output, inputsTotalSats) → {string}

Validate the given transaction output.

  • Validates the presence and value of address.

  • Validates the presence and value of amountSats. If inputsTotalSats is also passed, this will be taken into account when validating the amount.

Parameters:
Name Type Description
network module:networks.NETWORKS

bitcoin network

output module:outputs.TransactionOutput

output to validate

inputsTotalSats string | number | BigNumber

(optional) the total input amount in Satoshis

Source:
Returns:

empty if valid or corresponding validation message if not

Type
string
Example
import {validateOutput} from "unchained-bitcoin";
console.log(validateOutput(MAINNET, {amountSats: 100000, address: "2..."})); // "...address is invalid..."
console.log(validateOutput(MAINNET, {amountSats: 100000, address: "3..."})); // ""
console.log(validateOutput(MAINNET, {amountSats: 100000, address: "3..."}, 10000)); // "Amount is too large."

(static) validateOutputAmount(amountSats, inputsTotalSats) → {string}

Validate the given output amount (in Satoshis).

  • Must be a parseable as a number.

  • Cannot be negative (zero is OK).

  • Cannot be smaller than the limit set by DUST_LIMIT_SATS.

  • Cannot exceed the total input amount (this check is only run if inputsTotalSats is passed.

Parameters:
Name Type Description
amountSats string | number | BigNumber

output amount in Satoshis

inputsTotalSats string | number | BigNumber

(optional) total input amount in Satoshis

Source:
Returns:

empty if valid or corresponding validation message if not

Type
string
Example
import {validateOutputAmount} from "unchained-bitcoin";
console.log(validateOutputAmount(-100, 1000000) // "Output amount must be positive."
console.log(validateOutputAmount(0, 1000000) // "Output amount must be positive."
console.log(validateOutputAmount(10, 1000000) // "Output amount is too small."
console.log(validateOutputAmount(1000000, 100000) // "Output amount is too large."
console.log(validateOutputAmount(100000, 1000000) // ""

(static) validateOutputs(network, outputs, inputsTotalSatsopt) → {string}

Validates the given transaction outputs.

Returns an error message if there are no outputs. Passes each output to validateOutput.

Parameters:
Name Type Attributes Description
network module:networks.NETWORKS

bitcoin network

outputs Array.<module:outputs.TransactionOutput>

outputs to validate

inputsTotalSats string | number | BigNumber <optional>

(optional) the total input amount in Satoshis

Source:
Returns:

empty if valid or corresponding validation message if not

Type
string

Type Definitions

TransactionOutput

Represents an output in a transaction.

Type:
  • Object
Properties:
Name Type Attributes Description
address string

the output address

amountSats string | number | BigNumber

output amount in Satoshis

multisig Multisig <optional>

output multisig for a change address

Source: