MCPcopy Create free account
hub / github.com/CashScript/cashscript / TransactionBuilder

Class TransactionBuilder

packages/cashscript/src/TransactionBuilder.ts:75–633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73 * transaction can be built (`build`), debugged (`debug`), or broadcast (`send`).
74 */
75export class TransactionBuilder {
76 public provider: NetworkProvider;
77 public inputs: UnlockableUtxo[] = [];
78 public outputs: Output[] = [];
79
80 public locktime: number = 0;
81 public options: TransactionBuilderOptions;
82
83 private changeLocks: Record<string, boolean> = {};
84
85 /**
86 * Create a new TransactionBuilder.
87 *
88 * @param options - Builder options, including the network provider and optional fee/burn limits.
89 */
90 constructor(
91 options: TransactionBuilderOptions,
92 ) {
93 this.provider = options.provider;
94 this.options = {
95 allowImplicitFungibleTokenBurn: options.allowImplicitFungibleTokenBurn ?? false,
96 ...options,
97 };
98 }
99
100 /**
101 * Add a single UTXO as an input to the transaction.
102 *
103 * @param utxo - The UTXO to spend.
104 * @param unlocker - The unlocker to generate the unlocking bytecode for this input. Typically
105 * obtained from `contract.unlock.<functionName>(...args)` or `signatureTemplate.unlockP2PKH()`.
106 * @param options - Optional per-input options such as a custom sequence number.
107 * @returns This builder for chaining.
108 * @throws If the UTXO is invalid.
109 */
110 addInput(utxo: Utxo, unlocker: Unlocker, options?: InputOptions): this {
111 return this.addInputs([utxo], unlocker, options);
112 }
113
114 /**
115 * Add multiple UTXOs to the transaction that all share the same unlocker.
116 *
117 * @param utxos - The UTXOs to spend.
118 * @param unlocker - The shared unlocker used to unlock all provided UTXOs.
119 * @param options - Optional per-input options applied to every added input.
120 * @returns This builder for chaining.
121 * @throws If any UTXO is invalid.
122 */
123 addInputs(utxos: Utxo[], unlocker: Unlocker, options?: InputOptions): this;
124
125 /**
126 * Add multiple UTXOs that each carry their own unlocker.
127 *
128 * @param utxos - UTXOs that have already been paired with their individual unlockers.
129 * @returns This builder for chaining.
130 * @throws If any UTXO is missing its unlocker.
131 */
132 addInputs(utxos: UnlockableUtxo[]): this;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected