The version of the transaction.
The cell dependencies of the transaction.
The header dependencies of the transaction.
The inputs of the transaction.
The outputs of the transaction.
The data associated with the outputs.
The witnesses of the transaction.
The version of the transaction.
The cell dependencies of the transaction.
The header dependencies of the transaction.
The inputs of the transaction.
The outputs of the transaction.
The data associated with the outputs.
The witnesses of the transaction.
Static
Optional
byteThe bytes length of the entity, if it is fixed, otherwise undefined
Static
defaultCreates a default Transaction instance with empty fields.
A default Transaction instance.
Copy every properties from another transaction.
Creates a deep copy of the transaction. This method creates a new Transaction instance with all nested objects cloned, ensuring that modifications to the cloned transaction do not affect the original.
A new Transaction instance that is a deep copy of the current transaction.
const originalTx = Transaction.from({
version: 0,
inputs: [{ previousOutput: { txHash: "0x...", index: 0 } }],
outputs: [{ capacity: 1000n, lock: lockScript }],
outputsData: ["0x"],
witnesses: ["0x"]
});
const clonedTx = originalTx.clone();
// Modifications to clonedTx won't affect originalTx
clonedTx.addOutput({ capacity: 2000n, lock: anotherLockScript });
console.log(originalTx.outputs.length); // Still 1
console.log(clonedTx.outputs.length); // Now 2
The clone operation performs deep copying for:
The following are shallow copied (references to immutable data):
Static
fromCreates a Transaction instance from a TransactionLike object.
A TransactionLike object or an instance of Transaction.
A Transaction instance.
Static
fromCreates a Transaction instance from a Lumos skeleton.
The Lumos transaction skeleton.
A Transaction instance.
Static
hashComputes the signing hash information for a given script.
The script associated with the transaction, represented as a ScriptLike object.
The client for complete extra infos in the transaction.
A promise that resolves to an object containing the signing message and the witness position, or undefined if no matching input is found.
Find the first occurrence of a input with the specified lock id
The script associated with the transaction, represented as a ScriptLike object without args.
The client for complete extra infos in the transaction.
A promise that resolves to the found index
Find the first occurrence of a input with the specified lock
The script associated with the transaction, represented as a ScriptLike object.
The client for complete extra infos in the transaction.
A promise that resolves to the prepared transaction
Find the last occurrence of a input with the specified lock
The script associated with the transaction, represented as a ScriptLike object.
The client for complete extra infos in the transaction.
A promise that resolves to the prepared transaction
Add cell deps if they are not existed
Rest
...cellDepLikes: (CellDepLike | CellDepLike[])[]The cell deps to add
Add cell deps at the start if they are not existed
Rest
...cellDepLikes: (CellDepLike | CellDepLike[])[]The cell deps to add
Add cell dep from infos if they are not existed
A client for searching cell deps
Rest
...cellDepInfoLikes: (CellDepInfoLike | CellDepInfoLike[])[]The cell dep infos to add
Add cell deps from known script
The client for searching known script and cell deps
Rest
...scripts: (KnownScript | KnownScript[])[]The known scripts to add
Set output data at index.
The index of the output data.
The data to set.
add input
The cell input.
get output
The cell output index
Add output
The cell output to add
optional output data
Get witness at index as WitnessArgs
The index of the witness.
The witness parsed as WitnessArgs.
Set witness at index by WitnessArgs
The index of the witness.
The WitnessArgs to set.
Set witness at index
The index of the witness.
The witness to set.
Prepare dummy witness for sighash all method
The script associated with the transaction, represented as a ScriptLike object.
The length of dummy lock bytes.
The client for complete extra infos in the transaction.
A promise that resolves to the prepared transaction
Optional
capacityTweak: NumLikeOptional
filter: ClientCollectableSearchKeyFilterLikeOptional
filter: ClientCollectableSearchKeyFilterLikeComplete inputs by UDT balance
This method succeeds only if enough balance is collected.
It will try to collect at least two inputs, even when the first input already contains enough balance, to avoid extra occupation fees introduced by the change cell. An edge case: If the first cell has the same amount as the output, a new cell is not needed.
The signer to complete the inputs.
The type script of the UDT.
Optional
balanceTweak: NumLikeThe tweak of the balance.
A promise that resolves to the number of inputs added.
Optional
filter: ClientCollectableSearchKeyFilterLikeOptional
filter: ClientCollectableSearchKeyFilterLikeCompletes the transaction fee by adding inputs and handling change outputs. This method automatically calculates the required fee based on the transaction size and fee rate, adds necessary inputs to cover the fee, and handles change outputs through the provided change function.
The signer to complete inputs from and prepare the transaction.
A function that handles change capacity. It receives the transaction and excess capacity, and should return the additional capacity needed (0 if change is handled successfully, positive number if more capacity is needed for change cell creation).
Optional
expectedFeeRate: NumLikeThe expected fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
Optional
filter: ClientCollectableSearchKeyFilterLikeOptional filter for selecting cells when adding inputs.
Optional
options: { Optional configuration object.
A promise that resolves to a tuple containing: - The number of inputs added during the process - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
const [addedInputs, hasChange] = await tx.completeFee(
signer,
(tx, capacity) => {
if (capacity >= 61_00000000n) { // Minimum for a change cell
tx.addOutput({ capacity, lock: changeScript });
return 0;
}
return 61_00000000n; // Need more capacity for change cell
},
1000n // 1000 shannons per 1000 bytes
);
Optional
feeRate: NumLikeOptional
filter: ClientCollectableSearchKeyFilterLikeOptional
options: { Static
encodeEncode the entity into bytes
The entity to encode
The encoded bytes
Static
decodeDecode the entity from bytes
The bytes to decode
The decoded entity
Static
fromCreate an entity from bytes
The created entity
Check if the entity is equal to another entity
The other entity to compare with
True if the entities are equal, false otherwise
Creates an instance of Transaction.