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

x/lucid/src/mod.ts>Core.TransactionBuilder

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 Core.TransactionBuilder
import { Core } from "https://deno.land/x/lucid@0.8.6/src/mod.ts";
const { TransactionBuilder } = Core;

Methods

add_certificate(certificate, script_witness)

Add certificate via a Certificates object

add_input(utxo, script_witness)
add_inputs_from(inputs, change_address)

This automatically selects and adds inputs from {inputs} consisting of just enough to cover the outputs that have already been added. This should be called after adding all certs/outputs/etc and will be an error otherwise. Adding a change output must be called after via TransactionBuilder::balance() inputs to cover the minimum fees. This does not, however, set the txbuilder's fee.

change_address is required here in order to determine the min ada requirement precisely

Add a single JSON metadatum using a TransactionMetadatumLabel and a String It will be securely added to existing or new metadata in this builder

Add a single JSON metadatum using a TransactionMetadatumLabel, a String, and a MetadataJsonSchema object It will be securely added to existing or new metadata in this builder

add_metadatum(key, val)

Add a single metadatum using TransactionMetadatumLabel and TransactionMetadatum objects It will be securely added to existing or new metadata in this builder

add_mint(
policy_id,
mint_assets,
script_witness,
)

Add a mint entry to this builder using a PolicyID and MintAssets object It will be securely added to existing or new Mint in this builder It will securely add assets to an existing PolicyID But it will replace/overwrite any existing mint assets with the same PolicyID first redeemer applied to a PolicyID is taken for all further assets added to the same PolicyID

add_native_script(native_script)

Add native scripts via a NativeScripts object

add_output(output)

Add explicit output via a TransactionOutput object

add_plutus_data(plutus_data)

Add plutus data via a PlutusData object

add_plutus_script(plutus_script)

Add plutus scripts via a PlutusScripts object

add_plutus_v2_script(plutus_script)

Add plutus v2 scripts via a PlutusScripts object

add_required_signer(required_signer)
add_withdrawal(
reward_address,
coin,
script_witness,
)
balance(change_address, datum)

Warning: this function will mutate the /fee/ field Make sure to call this function last after setting all other tx-body properties Editing inputs, outputs, mint, etc. after change been calculated might cause a mismatch in calculated fee versus the required fee

Returns full Transaction object with the body and the auxiliary data NOTE: witness_set will contain all mint_scripts if any been added or set NOTE: is_valid set to true

construct(
collateral_utxos,
collateral_change_address,
native_uplc,
)

Returns full Transaction object with the body and the auxiliary data

NOTE: witness_set will contain all mint_scripts if any been added or set

takes fetched ex units into consideration

add collateral utxos and collateral change receiver in case you redeem from plutus script utxos

async call

NOTE: is_valid set to true

fee_for_input(
address,
input,
amount,
)

calculates how much the fee would increase if you added a given output

calculates how much the fee would increase if you added a given output

does not include refunds or withdrawals

does not include fee

withdrawals and refunds

Return explicit input plus implicit input plus mint

Return explicit output plus implicit output plus burn (does not consider fee directly)

warning: sum of all parts of a transaction must equal 0. You cannot just set the fee to the min value and forget about it warning: min_fee may be slightly larger than the actual minimum fee (ex: a few lovelaces) this is done to simplify the library code, but can be fixed later

Returns a copy of the current mint state in the builder

Returns a copy of the current witness native scripts in the builder

set_auxiliary_data(auxiliary_data)

Set explicit auxiliary data via an AuxiliaryData object It might contain some metadata plus native or Plutus scripts

set_metadata(metadata)

Set metadata using a GeneralTransactionMetadata object It will be set to the existing or new auxiliary data in this builder

set_network_id(network_id)
set_ttl(ttl)
set_validity_start_interval(validity_start_interval)

Returns the TransactionBody.