Skip to content

UTXO selection/createTx: support changeOutput (script-based change) #131

@carloscjdev

Description

@carloscjdev

selectUTXO(..., { createTx: true }) requires changeAddress. Allow a richer changeOutput object so change can target script-only outputs (P2WSH, Taproot trees, P2A, etc.) without deriving an address.

API

type SelectUtxoOpts = {
  changeAddress?: string; // existing
  changeOutput?: {
    script?: Bytes;
    redeemScript?: Bytes;
    witnessScript?: Bytes;
    tapInternalKey?: Bytes;
    bip32Derivation?: [Bytes, { fingerprint: number; path: number[] }][];
  }; // NEW
  feePerByte: bigint;
  bip69?: boolean;
  createTx?: boolean;
  network?: Network;
};

Example

const ms = btc.p2wsh(btc.p2ms(2, [pub1, pub2, pub3]));
const sel = btc.selectUTXO(utxo, outs, 'default', {
  changeOutput: { script: ms.script, witnessScript: ms.witnessScript },
  feePerByte: 2n,
  createTx: true,
});

Behavior

  • If changeOutput is set → use it for change and ignore changeAddress.
  • Backward compatible when only changeAddress is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions