Mint with Smart Contract

Simple Smart Contract - Time-locked minting with authorized signer

circle-info

This guide provides a practical implementation of a mint validator. For a general explanation of script purposes and validator types, see Mint Validator.

Objective

  • Implement a simple Aiken smart contract for minting tokens

  • Demonstrate the mint purpose validator in action

  • Implement time constraints with validity_range

  • Require specific signers with extra_signatories

Where to Find the Code

The complete example is available in the Simple Contract repositoryarrow-up-right.

You can follow the README.mdarrow-up-right for setup instructions.

Smart Contract Overview

This example implements a minting policy with two validation conditions:

  1. Time-lock: Minting is restricted to transactions before a predefined expiration timestamp

  2. Authorized Signer: Only transactions signed by a specific key can mint tokens

The contract is written in Aiken and compiled to a Plutus script that produces a CIP-57 blueprint.

Implementation Example

Key Components for Minting Policy Transactions

When building a transaction to mint tokens with a time-locked policy, you need to include:

  1. Mint Array: Defines what tokens to create with their metadata

  2. Script Interactions: Provides the redeemer needed by the validator

  3. Required Signers: Ensures the transaction is signed by the authorized key

  4. Validity Interval: Sets the transaction time to comply with the time-lock

Complete Implementation

The following example demonstrates the full process of building, signing, and submitting a transaction that mints tokens with our time-locked policy:

Important Technical Details

Transaction Validation

The transaction will only succeed if the time-lock and signature conditions are met:

circle-exclamation

Signing the Transaction

This example requires a multi-signature transaction where both the customer wallet and the admin wallet must sign:

circle-info

Real-World Implementation

In production applications:

  • Customer/User signatures would typically be handled in the frontend using wallet connectors like Weldarrow-up-right. These connectors will pass the signatures to the transactions/submit endpoint.

  • Admin signatures should be applied to the transaction on a secure server.

circle-info

Both signatures are required for different reasons:

  1. Customer signature: Required because they own the inputs (UTXOs) being used to pay transaction fees

  2. Admin signature: Required by the minting policy's extra_signatories condition

If either signature is missing, the transaction will fail.

Last updated

Was this helpful?