CCC Docs
    Preparing search index...

    Hierarchy

    Index

    Getter

    • get outputCells(): Iterable<CellAny>

      Provides an iterable over the transaction's output cells.

      This getter is a convenient way to iterate through all the output cells (CellAny) of the transaction, combining the outputs and outputsData arrays. It can be used with for...of loops or other iterable-consuming patterns.

      Returns Iterable<CellAny>

      An Iterable<CellAny> that yields each output cell of the transaction.

      for (const cell of tx.outputCells) {
      console.log(`Output cell capacity: ${cell.cellOutput.capacity}`);
      }

    Other

    • Creates an instance of Transaction.

      Parameters

      • version: bigint

        The version of the transaction.

      • cellDeps: CellDep[]

        The cell dependencies of the transaction.

      • headerDeps: `0x${string}`[]

        The header dependencies of the transaction.

      • inputs: CellInput[]

        The inputs of the transaction.

      • outputs: CellOutput[]

        The outputs of the transaction.

      • outputsData: `0x${string}`[]

        The data associated with the outputs.

      • witnesses: `0x${string}`[]

        The witnesses of the transaction.

      Returns Transaction

    version: bigint

    The version of the transaction.

    cellDeps: CellDep[]

    The cell dependencies of the transaction.

    headerDeps: `0x${string}`[]

    The header dependencies of the transaction.

    inputs: CellInput[]

    The inputs of the transaction.

    outputs: CellOutput[]

    The outputs of the transaction.

    outputsData: `0x${string}`[]

    The data associated with the outputs.

    witnesses: `0x${string}`[]

    The witnesses of the transaction.

    • Copy every properties from another transaction. This method replaces all properties of the current transaction with those from the provided transaction.

      Parameters

      • txLike: TransactionLike

        The transaction-like object to copy properties from.

      Returns void

      this.copy(Transaction.default());
      
    • 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.

      Returns Transaction

      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:

      • Cell dependencies (cellDeps) - each CellDep is cloned
      • Inputs - each CellInput is cloned
      • Outputs - each CellOutput is cloned

      The following are shallow copied (references to immutable data):

      • Header dependencies (headerDeps) - Hex strings are immutable
      • Output data (outputsData) - Hex strings are immutable
      • Witnesses - Hex strings are immutable
      • Version - bigint is immutable
    • Creates a Transaction instance from a TransactionLike object.

      Parameters

      • tx: TransactionLike

        A TransactionLike object or an instance of Transaction.

      Returns Transaction

      A Transaction instance.

      const transaction = Transaction.from({
      version: 0,
      cellDeps: [],
      headerDeps: [],
      inputs: [],
      outputs: [],
      outputsData: [],
      witnesses: []
      });
    • Returns string

      Use ccc.stringify instead. stringify the tx to JSON string.

    • Converts the raw transaction data to bytes.

      Returns Bytes

      A Uint8Array containing the raw transaction bytes.

      const rawTxBytes = transaction.rawToBytes();
      
    • Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense. To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.

      Returns `0x${string}`

      The hash of the transaction.

      const txHash = transaction.hash();
      
    • Calculates the hash of the transaction with witnesses.

      Returns `0x${string}`

      The hash of the transaction with witnesses.

      const txFullHash = transaction.hashFull();
      
    • Hashes a witness and updates the hasher.

      Parameters

      • witness: BytesLike

        The witness to hash.

      • hasher: Hasher

        The hasher instance to update.

      Returns void

      Transaction.hashWitnessToHasher("0x...", hasher);
      
    • Computes the signing hash information for a given script.

      Parameters

      • scriptLike: ScriptLike

        The script associated with the transaction, represented as a ScriptLike object.

      • client: Client

        The client for complete extra infos in the transaction.

      • hasher: Hasher = ...

      Returns Promise<undefined | { message: `0x${string}`; position: number }>

      A promise that resolves to an object containing the signing message and the witness position, or undefined if no matching input is found.

      const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
      if (signHashInfo) {
      console.log(signHashInfo.message); // Outputs the signing message
      console.log(signHashInfo.position); // Outputs the witness position
      }
    • Find the first occurrence of a input with the specified lock id

      Parameters

      • scriptIdLike: Pick<ScriptLike, "codeHash" | "hashType">

        The script associated with the transaction, represented as a ScriptLike object without args.

      • client: Client

        The client for complete extra infos in the transaction.

      Returns Promise<undefined | number>

      A promise that resolves to the found index

      const index = await tx.findInputIndexByLockId(scriptIdLike, client);
      
    • Find the first occurrence of a input with the specified lock

      Parameters

      • scriptLike: ScriptLike

        The script associated with the transaction, represented as a ScriptLike object.

      • client: Client

        The client for complete extra infos in the transaction.

      Returns Promise<undefined | number>

      A promise that resolves to the found index, or undefined if no matching input is found.

      const index = await tx.findInputIndexByLock(scriptLike, client);
      
    • Find the last occurrence of a input with the specified lock

      Parameters

      • scriptLike: ScriptLike

        The script associated with the transaction, represented as a ScriptLike object.

      • client: Client

        The client for complete extra infos in the transaction.

      Returns Promise<undefined | number>

      A promise that resolves to the found index, or undefined if no matching input is found.

      const index = await tx.findLastInputIndexByLock(scriptLike, client);
      
    • Add cell deps from known script

      Parameters

      Returns Promise<void>

      tx.addCellDepsOfKnownScripts(client, KnownScript.OmniLock);
      
    • Set output data at index.

      Parameters

      • index: number

        The index of the output data.

      • data: BytesLike

        The data to set.

      Returns void

      tx.setOutputDataAt(0, "0x00");
      
    • Adds an output to the transaction.

      This method supports two overloads for adding an output:

      1. By providing a CellAnyLike object, which encapsulates both cellOutput and outputData.
      2. By providing a CellOutputLike object and an optional outputData.

      Parameters

      Returns number

      The new number of outputs in the transaction.

      // 1. Add an output using a CellAnyLike object
      const newLength1 = tx.addOutput({
      cellOutput: { lock: recipientLock }, // capacity is calculated automatically
      outputData: "0x1234",
      });

      // 2. Add an output using CellOutputLike and data separately
      const newLength2 = tx.addOutput({ lock: recipientLock }, "0xabcd");
    • Adds an output to the transaction.

      This method supports two overloads for adding an output:

      1. By providing a CellAnyLike object, which encapsulates both cellOutput and outputData.
      2. By providing a CellOutputLike object and an optional outputData.

      Parameters

      • outputLike: CellOutputLike
      • OptionaloutputDataLike: null | BytesLike

        Optional data for the cell output. Defaults to "0x" if not provided in the first argument.

      Returns number

      The new number of outputs in the transaction.

      // 1. Add an output using a CellAnyLike object
      const newLength1 = tx.addOutput({
      cellOutput: { lock: recipientLock }, // capacity is calculated automatically
      outputData: "0x1234",
      });

      // 2. Add an output using CellOutputLike and data separately
      const newLength2 = tx.addOutput({ lock: recipientLock }, "0xabcd");
    • Get witness at index as WitnessArgs

      Parameters

      • index: number

        The index of the witness.

      Returns undefined | WitnessArgs

      The witness parsed as WitnessArgs.

      const witnessArgs = await tx.getWitnessArgsAt(0);
      
    • Set witness at index by WitnessArgs

      Parameters

      • index: number

        The index of the witness.

      • witness: WitnessArgs

        The WitnessArgs to set.

      Returns void

      await tx.setWitnessArgsAt(0, witnessArgs);
      
    • Set witness at index

      Parameters

      • index: number

        The index of the witness.

      • witness: BytesLike

        The witness to set.

      Returns void

      await tx.setWitnessAt(0, witness);
      
    • Prepare dummy witness for sighash all method

      Parameters

      • scriptLike: ScriptLike

        The script associated with the transaction, represented as a ScriptLike object.

      • lockLen: number

        The length of dummy lock bytes.

      • client: Client

        The client for complete extra infos in the transaction.

      Returns Promise<void>

      A promise that resolves to the prepared transaction

      await tx.prepareSighashAllWitness(scriptLike, 85, client);
      
    • Complete 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.

      Parameters

      • from: Signer

        The signer to complete the inputs.

      • type: ScriptLike

        The type script of the UDT.

      • OptionalbalanceTweak: NumLike

        The tweak of the balance.

      Returns Promise<number>

      A promise that resolves to the number of inputs added.

    • Completes 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.

      Parameters

      • from: Signer

        The signer to complete inputs from and prepare the transaction.

      • change: (tx: Transaction, capacity: bigint) => NumLike | Promise<NumLike>

        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).

      • OptionalexpectedFeeRate: NumLike

        The expected fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.

      • Optionalfilter: ClientCollectableSearchKeyFilterLike

        Optional filter for selecting cells when adding inputs.

      • Optionaloptions: { feeRateBlockRange?: NumLike; maxFeeRate?: NumLike; shouldAddInputs?: boolean }

        Optional configuration object.

        • OptionalfeeRateBlockRange?: NumLike

          Block range for fee rate calculation when expectedFeeRate is not provided.

        • OptionalmaxFeeRate?: NumLike

          Maximum allowed fee rate.

        • OptionalshouldAddInputs?: boolean

          Whether to add inputs automatically. Defaults to true.

      Returns Promise<[number, boolean]>

      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)

      When there's not enough capacity to cover the fee.

      When the change function doesn't properly handle the available capacity.

      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
      );
    • Completes the transaction fee by adding inputs and creating a change output with the specified lock script. This is a convenience method that automatically creates a change cell with the provided lock script when there's excess capacity after paying the transaction fee.

      Parameters

      • from: Signer

        The signer to complete inputs from and prepare the transaction.

      • change: ScriptLike

        The lock script for the change output cell.

      • OptionalfeeRate: NumLike

        Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.

      • Optionalfilter: ClientCollectableSearchKeyFilterLike

        Optional filter for selecting cells when adding inputs.

      • Optionaloptions: { feeRateBlockRange?: NumLike; maxFeeRate?: NumLike; shouldAddInputs?: boolean }

        Optional configuration object.

        • OptionalfeeRateBlockRange?: NumLike

          Block range for fee rate calculation when feeRate is not provided.

        • OptionalmaxFeeRate?: NumLike

          Maximum allowed fee rate.

        • OptionalshouldAddInputs?: boolean

          Whether to add inputs automatically. Defaults to true.

      Returns Promise<[number, boolean]>

      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 changeScript = Script.from({
      codeHash: "0x...",
      hashType: "type",
      args: "0x..."
      });

      const [addedInputs, hasChange] = await tx.completeFeeChangeToLock(
      signer,
      changeScript,
      1000n // 1000 shannons per 1000 bytes
      );
    • Completes the transaction fee using the signer's recommended address for change. This is a convenience method that automatically uses the signer's recommended address as the change destination, making it easier to complete transactions without manually specifying a change address.

      Parameters

      • from: Signer

        The signer to complete inputs from and prepare the transaction.

      • OptionalfeeRate: NumLike

        Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.

      • Optionalfilter: ClientCollectableSearchKeyFilterLike

        Optional filter for selecting cells when adding inputs.

      • Optionaloptions: { feeRateBlockRange?: NumLike; maxFeeRate?: NumLike; shouldAddInputs?: boolean }

        Optional configuration object.

        • OptionalfeeRateBlockRange?: NumLike

          Block range for fee rate calculation when feeRate is not provided.

        • OptionalmaxFeeRate?: NumLike

          Maximum allowed fee rate.

        • OptionalshouldAddInputs?: boolean

          Whether to add inputs automatically. Defaults to true.

      Returns Promise<[number, boolean]>

      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.completeFeeBy(
      signer,
      1000n // 1000 shannons per 1000 bytes
      );

      // Change will automatically go to signer's recommended address
    • Completes the transaction fee by adding excess capacity to an existing output. Instead of creating a new change output, this method adds any excess capacity to the specified existing output in the transaction.

      Parameters

      • from: Signer

        The signer to complete inputs from and prepare the transaction.

      • index: NumLike

        The index of the existing output to add excess capacity to.

      • OptionalfeeRate: NumLike

        Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.

      • Optionalfilter: ClientCollectableSearchKeyFilterLike

        Optional filter for selecting cells when adding inputs.

      • Optionaloptions: { feeRateBlockRange?: NumLike; maxFeeRate?: NumLike; shouldAddInputs?: boolean }

        Optional configuration object.

        • OptionalfeeRateBlockRange?: NumLike

          Block range for fee rate calculation when feeRate is not provided.

        • OptionalmaxFeeRate?: NumLike

          Maximum allowed fee rate.

        • OptionalshouldAddInputs?: boolean

          Whether to add inputs automatically. Defaults to true.

      Returns Promise<[number, boolean]>

      A promise that resolves to a tuple containing: - The number of inputs added during the process - A boolean indicating whether change was applied (true) or fee was paid without change (false)

      When the specified output index doesn't exist.

      // Add excess capacity to the first output (index 0)
      const [addedInputs, hasChange] = await tx.completeFeeChangeToOutput(
      signer,
      0, // Output index
      1000n // 1000 shannons per 1000 bytes
      );
    byteLength?: number

    The bytes length of the entity, if it is fixed, otherwise undefined

    • Encode the entity into bytes

      Parameters

      Returns Bytes

      The encoded bytes

      Will throw an error if the entity is not serializable

    • Decode the entity from bytes

      Parameters

      Returns Transaction

      The decoded entity

      Will throw an error if the entity is not serializable

    • Create an entity from bytes

      Parameters

      Returns Transaction

      The created entity

      Will throw an error if the entity is not serializable

    • Convert the entity to bytes

      Returns Bytes

      The bytes representation of the entity

    • Check if the entity is equal to another entity

      Parameters

      Returns boolean

      True if the entities are equal, false otherwise