Make Payments
Lucid Evolution provides several methods for making payments, each with its own specific use case:
Simple ADA Payment
For straightforward payments to a public key or native script address, use pay.ToAddress
:
const tx = await lucid
.newTx()
.pay.ToAddress("addr_test...", { lovelace: 5000000n })
.complete();
const signedTx = await tx.sign.withWallet().complete();
const txHash = await signedTx.submit();
Multiple Recipients
Chain multiple pay.ToAddress
calls to pay multiple recipients:
const tx = await lucid
.newTx()
.pay.ToAddress("addr_testa...", { lovelace: 5000000n })
.pay.ToAddress("addr_testb...", { lovelace: 5000000n })
.pay.ToAddress("addr_testc...", { lovelace: 5000000n })
.complete();
const signedTx = await tx.sign.withWallet().complete();
const txHash = await signedTx.submit();
Each pay.ToAddress
call creates a new UTxO, even for the same address. Lucid
Evolution considers the order of outputs.
Native Tokens
Lucid Evolution automatically adds the minimum ADA requirement for payments in Cardano Native Tokens (CNTs):
const policyId = "00...";
const assetName = "MyToken";
const tx = await lucid
.newTx()
.pay.ToAddress("addr_test...", { [policyId + fromText(assetName)]: 10n })
.complete();
const signedTx = await tx.sign.withWallet().complete();
const txHash = await signedTx.submit();
Attach Metadata
Attach metadata to your ADA payments:
const tx = await lucid
.newTx()
.pay.ToAddress("addr_test...", { lovelace: 5000000n })
.attachMetadata(1, { msg: "Hello from Anastasia Labs" })
.complete();
const signedTx = await tx.sign.withWallet().complete();
const txHash = await signedTx.submit();
Datum / Reference Script
For more complex scenarios, pay.ToAddressWithData
allows you to include a datum or a reference script. Lucid Evolution then implicitly adds the minimum ADA requirement for datums.
With a Datum
The datum can be attached in different ways:
// As hash - datum is attached to the witness set, with its hash stored in the UTxO
const tx = await lucid
.newTx()
.pay.ToAddressWithData(
"addr_test...",
{ kind: "hash", value: Data.to("31313131") },
{ lovelace: 5000000n }
)
.complete();
// As inline - datum stored directly in UTxO
const tx = await lucid
.newTx()
.pay.ToAddressWithData(
"addr_test...",
{ kind: "inline", value: Data.to("31313131") },
{ lovelace: 5000000n }
)
.complete();
With Script Reference
Deploy a reference script:
const deployRefScriptTx = await lucid
.newTx()
.pay.ToAddressWithData(
scriptAddress,
{ kind: "inline", value: datum },
{ lovelace: 5_000_000n },
referenceScript // The script to be stored as a reference for subsequent transactions
)
.complete();
Later, transactions can reference the deployed script instead of including it, for example:
const allUTxOs = await lucid.utxosAt(scriptAddress);
const refScriptUTxO = allUTxOs.filter((utxo) => utxo.scriptRef); // Find UTxO with reference script depending on your use case
const useRefScriptTx = await lucid
.newTx()
.collectFrom([utxoToSpend], redeemer) // Specify your action, for example: which UTxO to spend and which redeemer to use
.readFrom([refScriptUTxO]) // Reference the script UTxO
.complete();
Reference scripts are stored on-chain in a UTxO and can be "referenced" by other transactions, reducing transaction sizes and costs. This way the script only needs to be stored once and can be reused by multiple transactions.
Plutus Script
Use pay.ToContract
for payments to a Plutus script address. This method ensures that a datum is provided.
const tx = await lucid
.newTx()
.pay.ToContract(
"addr_test...",
{ kind: "inline", value: Data.to("31313131") },
{ lovelace: 5000000n }
)
.complete();
const signedTx = await tx.sign.withWallet().complete();
const txHash = await signedTx.submit();
Minimum ADA Calculation
Every UTxO on Cardano must hold a minimum amount of ADA (lovelace), which increases with UTxO size (in bytes). This is particularly relevant for native tokens, as their metadata (e.g., names, quantities, policies) adds to the UTxO size. A utility function for this is:
const minLovelace = calculateMinLovelaceFromUTxO(
coinsPerUtxoByte, // from protocol parameters
utxo
);
The minimum ADA requirement acts as “rent” for blockchain storage, ensuring UTxOs cover their storage costs and preventing spam from tiny UTxOs (dust), which could bloat the blockchain state and degrade performance. It also guarantees sufficient ADA to cover future transaction fees for moving tokens.