Creates a funding transaction for transferring BTC between addresses.
TransactionFactory
Overview
The full source code is available on GitHub at TransactionFactory.ts.
Import
import { TransactionFactory } from '@btc-vision/transaction';Instance Methods
public async createBTCTransfer(
parameters: IFundingTransactionParameters | IFundingTransactionParametersWithoutSigner
): Promise<BitcoinTransferBase>| Name | Type | Required | Description |
|---|---|---|---|
| parameters | IFundingTransactionParameters | IFundingTransactionParametersWithoutSigner | Yes | The funding transaction parameters including amount, sender, recipient, UTXOs, and fee configuration. |
When parameters is IFundingTransactionParameters
| Parameter | Required | Description |
|---|---|---|
| signer | Yes | The signing key for the transaction. |
| mldsaSigner | Yes | ML-DSA quantum signer, or null. |
| network | Yes | Bitcoin network (networks.bitcoin, networks.testnet, etc.) |
| utxos | Yes | Unspent outputs to fund the transaction. |
| from | Yes | Sender address. |
| to | Yes | Recipient address. |
| feeRate | Yes | Fee rate in sat/vB. |
| priorityFee | Yes | OP_NET priority fee in satoshis. |
| gasSatFee | Yes | OP_NET gas fee in satoshis. |
| amount | Yes | Amount to send in satoshis. |
| splitInputsInto | No | Split the payment into N equal outputs (default: 1). |
| autoAdjustAmount | No | Deduct fees from amount (send-max mode). |
| feeUtxos | No | Separate UTXOs used exclusively for fees. |
When parameters is IFundingTransactionParametersWithoutSigner
| Parameter | Required | Description |
|---|
| Type | Description |
|---|---|
| Promise<BitcoinTransferBase> | The signed transaction result containing the transaction hex, estimated fees, next UTXOs, and input UTXOs. |
| Type | Description |
|---|---|
| Error('Field "to" not provided.') | When 'to' is not provided. |
| Error('Field "from" not provided.') | When 'from' is not provided. |
| Error('Field "signer" not provided, OP_WALLET not detected.') | When 'signer' is not provided and OP_WALLET is not detected. |
public async createCancellableTransaction(
params: ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner,
): Promise<CancelledTransaction>Creates a cancellable transaction.
| Name | Type | Required | Description |
|---|---|---|---|
| params | ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner | Yes | The cancel transaction parameters including the compiled target script of the transaction being cancelled. |
When parameters is ICancelTransactionParameters
| Parameter | Required | Description |
|---|---|---|
| signer | Yes Browser: omit |
The signing key (omit in browser for OP_WALLET). |
| mldsaSigner | Yes Browser: omit |
ML-DSA quantum signer. |
| network | Yes | Bitcoin network (networks.bitcoin, networks.testnet, etc.) |
| utxos | Yes | The stuck UTXOs to recover. |
| from | Yes | Original sender address (receives refund). |
| to | Yes | Recovery destination address. |
| feeRate | Yes | Fee rate in sat/vB. |
| compiledTargetScript | Yes | The compiled script from the original transaction. |
When parameters is ICancelTransactionParametersWithoutSigner
| Parameter | Required | Description |
|---|
| Type | Description |
|---|---|
| Promise<CancelledTransaction> | The cancelled transaction result containing the transaction hex, next UTXOs, and input UTXOs. |
| Type | Description |
|---|---|
| Error('Field "to" not provided.') | When 'to' is not provided. |
| Error('Field "from" not provided.') | When 'from' is not provided. |
| Error('Missing at least one UTXO.') | When there is not UTXO provided. |
| Error('Field "signer" not provided, OP_WALLET not detected.') | When 'signer' is not provided and OP_WALLET is not detected. |
Cancel transactions do not use priorityFee or gasSatFee. These fields are omitted from the parameter interface.
public async createCustomScriptTransaction(
interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner,
): Promise<[string, string, UTXO[], UTXO[]]>Generates a transaction with a custom Bitcoin script for advanced use cases. Follows the two-transaction model (funding + custom script).
| Name | Type | Required | Description |
|---|---|---|---|
| params | ICustomTransactionParameters | ICustomTransactionWithoutSigner | Yes | The custom transaction parameters including script stack, witnesses, optional annex, and target address. |
When parameters is ICustomTransactionParameters
| Parameter | Required | Description |
|---|---|---|
| signer | Yes | The signing key. |
| mldsaSigner | Yes | ML-DSA quantum signer. |
| network | Yes | Bitcoin network (networks.bitcoin, networks.testnet, etc.) |
| utxos | Yes | Unspent outputs. |
| from | Yes | Sender address. |
| to | Yes | Recipient address. |
| feeRate | Yes | Fee rate in sat/vB. |
| priorityFee | Yes | OP_NET priority fee in satoshis. |
| gasSatFee | Yes | OP_NET gas fee in satoshis. |
| script | Yes | The custom Bitcoin script to execute. |
| script | Yes | The custom Bitcoin script to execute. |
| witnesses | Yes | Witness data for the script. |
| annex | No | Optional Taproot annex payload (without the 0x50 prefix). |
When parameters is ICustomTransactionWithoutSigner
| Parameter | Required | Description |
|---|
| Type | Description |
|---|---|
| Promise<CancelledTransaction> | A tuple containing the funding transaction hex, custom transaction hex, next UTXOs, and input UTXOs. |
| Type | Description |
|---|---|
| Error('Field "to" not provided.') | When 'to' is not provided. |
| Error('Field "from" not provided.') | When 'from' is not provided. |
| Error('Missing at least one UTXO.') | When there is not UTXO provided. |
| Error('Field "signer" not provided, OP_WALLET not detected.') | When 'signer' is not provided and OP_WALLET is not detected. |
| Error('Field "signer" not provided, OP_WALLET not detected.') | When 'signer' is not provided and OP_WALLET is not detected. |
| Error('Could not sign funding transaction.') | When the fees estimation for the funding transaction cannot be created. |
| Error('Could not sign funding transaction.') | When the funding transaction cannot be created. |
public async signConsolidatedInteraction(
interactionParameters: IConsolidatedInteractionParameters,
): Promise<ConsolidatedInteractionResponse>
Drop-in replacement for signInteraction that bypasses BIP110/Bitcoin Knots censorship. Uses P2WSH with HASH160 commitments (the CHCT system) instead of Tapscript. Produces a setup transaction and a reveal transaction.
| Name | Type | Required | Description |
|---|---|---|---|
| interactionParameters | IConsolidatedInteractionParameters | Yes | The deployment parameters including bytecode, calldata, challenge solution, and signer. |
| Parameter | Required | Description |
|---|---|---|
| signer | Yes | The signing key (no browser wallet support). |
| mldsaSigner | Yes | ML-DSA quantum signer. |
| network | Yes | Bitcoin network (networks.bitcoin, networks.testnet, etc.) |
| utxos | Yes | Unspent outputs. |
| from | Yes | Caller address. |
| to | Yes | Contract address to call. |
| feeRate | Yes | Fee rate in sat/vB. |
| priorityFee | Yes | OP_NET priority fee in satoshis. |
| gasSatFee | Yes | OP_NET gas fee in satoshis. |
| calldata | Yes | ABI-encoded function call data. |
| challenge | Yes | Epoch challenge solution. |
| maxChunkSize | No | Max bytes per stack item (default: 80, P2WSH policy limit). |
| Type | Description |
|---|---|
| Promise<ConsolidatedInteractionResponse> | Both setup and reveal transactions. |
| Type | Description |
|---|---|
| Error('Field "e;to"e; not provided.') | When 'to' is not provided. |
| Error('Field "e;from"e; not provided.') | When 'from' is not provided. |
| Error('Missing at least one UTXO.') | When the utxos array is empty. Provide at least one unspent transaction output to fund the transaction. |
| Error('Field "e;signer"e; not provided.') | No signer was provided. |
| Error('Field "e;challenge"e; not provided.') | No challenge was provided. |
public async signDeployment(
deploymentParameters: IDeploymentParameters,
): Promise<DeploymentResult>
Deploys a smart contract using the two-transaction model. Produces a funding transaction and a deployment transaction.
| Name | Type | Required | Description |
|---|---|---|---|
| deploymentParameters | IDeploymentParameters | Yes | The deployment parameters including bytecode, calldata, challenge solution, and signer. |
| Parameter | Required | Description |
|---|---|---|
| signer | Yes Browser: omit |
The signing key (omit in browser for OP_WALLET). |
| mldsaSigner | Yes Browser: omit |
ML-DSA quantum signer. |
| network | Yes | Bitcoin network (networks.bitcoin, networks.testnet, etc.) |
| utxos | Yes | Unspent outputs to fund the deployment. |
| from | Yes | Deployer address. |
| feeRate | Yes | Fee rate in sat/vB. |
| priorityFee | Yes | OP_NET priority fee in satoshis. |
| gasSatFee | Yes | OP_NET gas fee in satoshis. |
| bytecode | Yes | Compiled contract bytecode. |
| calldata | No | Constructor parameters (ABI-encoded). |
| challenge | Yes | Epoch challenge solution. |
| randomBytes | No | 32 random bytes for script uniqueness (auto-generated if omitted). |
| Type | Description |
|---|---|
| Promise<DeploymentResult> | The deployment result containing the funding and deployment transaction hex, contract address, contract public key, remaining UTXOs, challenge, and input UTXOs. |
| Type | Description |
|---|---|
| Error('Field "signer" not provided, OP_WALLET not detected.') | When 'signer' is not provided and OP_WALLET is not detected. |
| Error('Failed to get challenge from deployment transaction') | When challenge cannot be obtained. |
| Error('Could not sign funding transaction.') | When the fees estimation for the funding transaction cannot be created. |
| Error('Could not sign funding transaction.') | When the funding transaction cannot be created. |
public async signInteraction(
interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner,
): Promise<InteractionResponse>
Calls a smart contract function using the two-transaction model. Produces a funding transaction and an interaction transaction. Automatically uses P2WDA mode when P2WDA UTXOs are detected.
| Name | Type | Required | Description |
|---|---|---|---|
| interactionParameters | IInteractionParameters | InteractionParametersWithoutSigner | Yes | The interaction parameters. |
| Parameter | Required | Description |
|---|---|---|
| signer | Yes Browser: omit |
The signing key (omit in browser for OP_WALLET). |
| mldsaSigner | Yes Browser: omit |
ML-DSA quantum signer. |
| network | Yes | Bitcoin network (networks.bitcoin, networks.testnet, etc.) |
| utxos | Yes | Unspent outputs. |
| from | Yes | Caller address |
| to | Yes | Contract address to call |
| feeRate | Yes | Fee rate in sat/vB. |
| priorityFee | Yes | OP_NET priority fee in satoshis. |
| gasSatFee | Yes | OP_NET gas fee in satoshis. |
| calldata | Yes | ABI-encoded function call data |
| challenge | Yes | Epoch challenge solution. |
| contract | No | Alternative contract identifier |
| randomBytes | No | 32 random bytes (auto-generated if omitted) |
| disableAutoRefund | No | Disable automatic refund output |
| loadedStorage | No | Pre-loaded contract storage for optimization |
| Type | Description |
|---|---|
| Promise<InteractionResponse> | The signed transaction. |
| Type | Description |
|---|---|
| Error('Field "e;to"e; not provided.') | When 'to' is not provided. |
| Error('Field "e;from"e; not provided.') | When 'from' is not provided. |
| Error('Missing at least one UTXO.') | When the utxos array is empty. Provide at least one unspent transaction output to fund the transaction. |
| Error('Field "e;signer"e; not provided, OP_WALLET not detected.') | No signer was provided and the OP_WALLET browser extension is not available. |
| Error('Failed to get challenge from interaction transaction') | When the funding transaction cannot be created. |
| Error('Could not sign funding transaction.') | The funding transaction signing failed. This may occur due to insufficient UTXOs, invalid signer, or network issues. |