BSV.Transaction.Builder (bsv_sdk v1.1.0)

Copy Markdown View Source

Pipe-friendly transaction builder.

Summary

Functions

Add an input from hex-encoded txid, vout, locking script hex, and satoshi amount. Raises on error.

Add an OP_RETURN output containing the given data pushes (0 satoshis).

Append a pre-built output to the transaction.

Add a P2PKH output paying to the given Base58Check address. Raises on invalid address.

Validate and finalize the transaction. Returns error if inputs or outputs are missing.

Create a new empty transaction.

Sign all inputs using the same signing template.

Sign a single input using the given signing template (e.g. P2PKH, Stas).

Functions

add_input(tx, prev_txid_hex, vout, locking_script_hex, satoshis)

Add an input from hex-encoded txid, vout, locking script hex, and satoshi amount. Raises on error.

add_op_return_output(tx, data_list)

@spec add_op_return_output(BSV.Transaction.t(), [binary()]) :: BSV.Transaction.t()

Add an OP_RETURN output containing the given data pushes (0 satoshis).

add_output(tx, output)

Append a pre-built output to the transaction.

add_p2pkh_output(tx, address_string, satoshis)

@spec add_p2pkh_output(BSV.Transaction.t(), String.t(), non_neg_integer()) ::
  BSV.Transaction.t()

Add a P2PKH output paying to the given Base58Check address. Raises on invalid address.

build(tx)

@spec build(BSV.Transaction.t()) :: {:ok, BSV.Transaction.t()} | {:error, term()}

Validate and finalize the transaction. Returns error if inputs or outputs are missing.

new()

@spec new() :: BSV.Transaction.t()

Create a new empty transaction.

sign_all_inputs(tx, template)

@spec sign_all_inputs(
  BSV.Transaction.t(),
  struct()
) :: {:ok, BSV.Transaction.t()} | {:error, term()}

Sign all inputs using the same signing template.

sign_input(tx, input_index, template)

@spec sign_input(BSV.Transaction.t(), non_neg_integer(), struct()) ::
  {:ok, BSV.Transaction.t()} | {:error, term()}

Sign a single input using the given signing template (e.g. P2PKH, Stas).