Documentation
Deep Dives
Pay Methods

Pay Methods

Evolution library provides several .pay methods to create transaction outputs on the Cardano blockchain. These methods allow you to send ADA, native tokens, attach datums, deploy reference scripts, and interact with smart contracts. This guide covers all the available pay methods and their use cases.

Ada Transfer

Straightforward pay function to a public key or script address:

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 considers the order of outputs.


Cardano Native Tokens

Minimum Ada requirement for native tokens is automatically handled by the library:

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();

Metadata

Attach metadata to your transaction output:

const tx = await lucid
  .newTx()
  .pay.ToAddress("addr_test...", { lovelace: 5000000n })
  .attachMetadata(1, { msg: "Wen Midgard?" })
  .complete();
 
const signedTx = await tx.sign.withWallet().complete();
const txHash = await signedTx.submit();

Datums

Include a datum to your transaction output:

// As hash
const tx = await lucid
  .newTx()
  .pay.ToAddressWithData(
    "addr_test...",
    { kind: "hash", value: Data.to("31313131") },
    { lovelace: 5000000n }
  )
  .complete();