Minting Assets
Lucid Evolution provides comprehensive tools for minting and burning tokens on the Cardano blockchain, supporting native scripts and Plutus-based minting policies.
Minting Policy
First, we need to create a minting policy for the assets we want to mint.
In this example, we'll use a native script time-locking policy with our wallet as the required signer:
const address = await lucid.wallet().address();
 
const mintingPolicy = scriptFromNative({
  type: "all",
  scripts: [
    { type: "sig", keyHash: paymentCredentialOf(address).hash },
    {
      type: "before",
      slot: unixTimeToSlot(lucid.config().network, Date.now() + 1000000),
    },
  ],
});Native scripts support various constructs: sig (signature), all (and), any (or), at_least (m-of-n), before (time lock), and after (time lock).
Derive the Policy ID
Next we derive the policy id from the minting policy script:
const policyId = mintingPolicyToId(mintingPolicy);Mint Assets
Now we can mint the intended tokens according to the policy logic:
const tx = await lucid
  .newTx()
  .mintAssets({
    [policyId + fromText("MyToken")]: 1n,
    [policyId + fromText("MyOtherToken")]: 1n,
  })
  .pay.ToAddress(address, { [policyId + fromText("MyToken")]: 1n })
  .validTo(Date.now() + 900000)
  .attach.MintingPolicy(mintingPolicy)
  .complete();
 
const signed = await tx.sign.withWallet().complete();
const txHash = await signed.submit();To burn tokens, use negative values with the mintAssets function:
const tx = await lucid
  .newTx()
  .mintAssets({
    [policyId + fromText("MyToken")]: -1n,
    [policyId + fromText("MyOtherToken")]: -1n,
  })
  .validTo(Date.now() + 900000)
  .attach.MintingPolicy(mintingPolicy)
  .complete();
 
const signed = await tx.sign.withWallet().complete();
const txHash = await signed.submit();Minting tokens creates them, but doesn't automatically send them to an
address, use pay.ToAddress() to send the newly minted tokens to a specific
address.
Important Considerations
- All assets minted in a single mintAssetscall should be of the same policy id
- You can chain multiple mintAssetscalls if you need to mint assets with different policy ids
- The minting policy must be attached to the transaction using attach.MintingPolicy
- Evolution supports Native,PlutusV1/V2/V3minting policies
- When using Plutus scripts, make sure to provide an appropriate redeemer