Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/lucid/src/lucid/tx.ts>Tx

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
Go to Latest
class Tx
import { Tx } from "https://deno.land/x/lucid@0.7.7/src/lucid/tx.ts";

Constructors

new
Tx(lucid: Lucid)

Properties

private
lucid: Lucid
private
tasks: ((that: Tx) => unknown)[]

Stores the tx instructions, which get executed after calling .complete()

txBuilder: Core.TransactionBuilder

Methods

Needs to be a public key address. The PaymentKeyHash is taken when providing a Base, Enterprise or Pointer address. The StakeKeyHash is taken when providing a Reward address.

Add a payment or stake key hash as a required signer of the transaction.

apply(callback: (thisTx: Tx) => unknown): Tx

Apply to the transaction.

applyIf(condition: boolean, callback: (thisTx: Tx) => unknown): Tx

Conditionally apply to the transaction.

attachMetadata(label: Label, metadata: Json): Tx

Converts strings to bytes if prefixed with '0x'.

collectFrom(utxos: UTxO[], redeemer?: Redeemer): Tx

A public key or native script input. With redeemer it's a plutus script input.

complete(options?: { changeAddress?: Address; datum?: { asHash?: Datum; inline?: Datum; }; coinSelection?: boolean; nativeUplc?: boolean; }): Promise<TxComplete>
compose(tx: Tx): Tx

Compose transactions (Similar to apply, but applies a tx object to the current tx instead).

delegateTo(
rewardAddress: RewardAddress,
poolId: PoolId,
redeemer?: Redeemer,
): Tx

Delegate to a stake pool.

deregisterStake(rewardAddress: RewardAddress, redeemer?: Redeemer): Tx

Deregister a reward address.

mintAssets(assets: Assets, redeemer?: Redeemer): Tx

All assets should be of the same policy id. You can chain mintAssets events together if you need to mint assets with different policy ids. If the plutus script doesn't need a redeemer, you still neeed to specifiy the empty redeemer.

payToAddress(address: Address, assets: Assets): Tx

Pay to a public key or native script address.

payToAddressWithData(
address: Address,
outputData: Datum | OutputData,
assets: Assets,
): Tx

Pay to a public key or native script address with datum or scriptRef.

payToContract(
address: Address,
outputData: Datum | OutputData,
assets: Assets,
): Tx

Pay to a plutus script address with datum or scriptRef.

readFrom(utxos: UTxO[]): Tx

Read data from utxos. These utxos are only referenced and not spent.

registerPool(poolParams: PoolParams): Tx

Register a stake pool. A pool deposit is required. The metadataUrl needs to be hosted already before making the registration.

registerStake(rewardAddress: RewardAddress): Tx

Register a reward address in order to delegate to a pool and receive rewards.

retirePool(poolId: PoolId, epoch: number): Tx

Retire a stake pool. The epoch needs to be the greater than the current epoch + 1 and less than current epoch + eMax. The pool deposit will be sent to reward address as reward after full retirement of the pool.

toString(): Promise<string>

Return the current transaction body in Hex encoded Cbor.

updatePool(poolParams: PoolParams): Tx

Update a stake pool. No pool deposit is required. The metadataUrl needs to be hosted already before making the update.

validFrom(unixTime: UnixTime): Tx
validTo(unixTime: UnixTime): Tx
withdraw(
rewardAddress: RewardAddress,
amount: Lovelace,
redeemer?: Redeemer,
): Tx