Constructors

  • Creates an instance of Transaction.

    Parameters

    • version: bigint

      The version of the transaction.

    • cellDeps: ccc.CellDep[]

      The cell dependencies of the transaction.

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

      The header dependencies of the transaction.

    • inputs: ccc.CellInput[]

      The inputs of the transaction.

    • outputs: ccc.CellOutput[]

      The outputs of the transaction.

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

      The data associated with the outputs.

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

      The witnesses of the transaction.

    Returns ccc.Transaction

Properties

version: bigint

The version of the transaction.

cellDeps: ccc.CellDep[]

The cell dependencies of the transaction.

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

The header dependencies of the transaction.

inputs: ccc.CellInput[]

The inputs of the transaction.

outputs: ccc.CellOutput[]

The outputs of the transaction.

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

The data associated with the outputs.

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

The witnesses of the transaction.

Methods

  • Copy every properties from another transaction.

    Parameters

    Returns void

    this.copy(Transaction.default());
    
  • Creates a Transaction instance from a TransactionLike object.

    Parameters

    • tx: TransactionLike

      A TransactionLike object or an instance of Transaction.

    Returns ccc.Transaction

    A Transaction instance.

    const transaction = Transaction.from({
    version: 0,
    cellDeps: [],
    headerDeps: [],
    inputs: [],
    outputs: [],
    outputsData: [],
    witnesses: []
    });
  • Converts the raw transaction data to bytes.

    Returns Uint8Array

    A Uint8Array containing the raw transaction bytes.

    const rawTxBytes = transaction.rawToBytes();
    
  • Converts the whole transaction data to bytes.

    Returns Uint8Array

    A Uint8Array containing the full transaction bytes.

    const txBytes = transaction.toBytes();
    
  • Calculates the hash of the transaction.

    Returns `0x${string}`

    The hash of the transaction.

    const txHash = transaction.hash();
    
  • 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 prepared transaction

    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 prepared transaction

    const index = await tx.findLastInputIndexByLock(scriptLike, client);
    
  • Add cell deps if they are not existed

    Parameters

    Returns void

    tx.addCellDeps(cellDep);
    
  • Add cell deps at the start if they are not existed

    Parameters

    Returns void

    tx.addCellDepsAtBegin(cellDep);
    
  • Add cell dep from infos if they are not existed

    Parameters

    Returns Promise<void>

    tx.addCellDepInfos(client, cellDepInfos);
    
  • 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.

    • witness: BytesLike

      The data to set.

    Returns void

    await tx.setOutputDataAt(0, "0x00");
    
  • Add output

    Parameters

    Returns void

    await tx.addOutput(cellOutput, "0xabcd");
    
  • Get witness at index as WitnessArgs

    Parameters

    • index: number

      The index of the witness.

    Returns undefined | ccc.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: ccc.WitnessArgs

      The WitnessArgs to set.

    Returns void

    await tx.setWitnessArgsAt(0, witnessArgs);
    
  • 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);
    
  • Type Parameters

    • T

    Parameters

    Returns Promise<{
        addedCount: number;
        accumulated?: T;
    }>