Hierarchy

Constructors

  • 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

Properties

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.

byteLength?: number

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

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 Transaction

    A Transaction instance.

    const transaction = Transaction.from({
    version: 0,
    cellDeps: [],
    headerDeps: [],
    inputs: [],
    outputs: [],
    outputsData: [],
    witnesses: []
    });
  • Creates a Transaction instance from a Lumos skeleton.

    Parameters

    Returns Transaction

    A Transaction instance.

    Will throw an error if an input's outPoint is missing.

    const transaction = Transaction.fromLumosSkeleton(skeleton);
    
  • Converts the raw transaction data to bytes.

    Returns Uint8Array

    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 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 | 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);
    
  • 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;
    }>

  • Encode the entity into bytes

    Parameters

    Returns Uint8Array

    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 Uint8Array

    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