Mint Example
This guide provides a complete Deno implementation for minting CIP-68 NFTs using parameterized smart contracts with the Anvil API.
Full Code Example
Implementation Overview
This example demonstrates:
Applying parameters to uploaded blueprints
Building transactions with preloaded scripts
Dual-wallet signing for smart contract authorization
Complete end-to-end minting workflow
Prerequisites
Before running this example, ensure you have:
Deno installed - Download here
Anvil API key - Get one from the Anvil dashboard
Two wallets with testnet ADA: (See Wallet CLI)
Customer wallet (pays fees, receives user token)
Admin wallet (provides key_hash parameter, signs transaction)
Uploaded CIP-68 blueprint - The original blueprint must be uploaded to the Anvil API first. See blueprint Management
Understanding of parameterized contracts - Parameters are applied at transaction time, not deployment time
Step-by-Step Implementation
Let's build a parameterized CIP-68 minting script step by step. Each section will explain the concept and show the corresponding code.
Step 1: Setup and Imports
First, we need to import the required dependencies and load our configuration files.
Create cip68-parameterized-mint.ts:
What's happening here:
We import Cardano Serialization Library for transaction signing
Load wallet files (customer pays fees, admin provides authorization)
Load the original blueprint (compiled from Aiken smart contract)
Set up API configuration and asset name
Step 2: Apply Parameters to Blueprint
The blueprint that we uploaded is generic. In order to make it custom for this collection. We need to apply the parameters to the smart contract, parameterized contracts are customized at transaction time. We apply the admin's key hash to create a personalized version of the contract:
What's happening here:
We call
/blueprints/apply-paramswith the original blueprint and admin key hashThe endpoint generates a new script with the admin key "baked in" as a parameter
We get back a new script hash, address, and complete parameterized script
Important: This parameterized script is NOT saved to the database - we must use it directly
Expected output:
Step 3: Build the Transaction Payload
Now we build the CIP-68 minting transaction. The key insight is that we include the parameterized script as a preloadedScript so the tx-builder can validate it:
What's happening here:
Mint array: Creates both reference (100) and user (222) tokens with the same base name
Script interactions: Tells the smart contract which assets we're minting via the redeemer
Outputs: Explicitly routes the reference token to the script address with metadata datum
Required signers: Ensures the admin (whose key was used in parameters) signs the transaction
Preloaded scripts: Includes our parameterized script so tx-builder can validate it
Key insight: The user token (222) automatically goes to the change address, while the reference token (100) needs an explicit output with custom datum in order to go to the script address.
Step 4: Build the Transaction
Finally, we build the transaction:
What's happening here:
The tx-builder validates our payload and creates a Cardano transaction
It includes the parameterized script from our
preloadedScriptsThe transaction is returned as a hex-encoded string ready for signing
Step 5: Sign with Both Wallets
CIP-68 smart contracts require signatures from both the customer (who pays fees) and the admin (who authorizes minting):
What's happening here:
We deserialize the transaction from hex format
Load both private keys (customer and admin)
Add both signatures to the witness set
Create the final signed transaction
Step 6: Submit to Network
Finally, we submit the signed transaction to the Cardano network:
What's happening here:
The signed transaction is submitted to the Cardano network
On success, we get back a transaction hash for tracking
Both CIP-68 tokens are now minted and distributed according to our rules
Expected output:
Running the Example
Prerequisites Setup
Upload the blueprint first using a separate upload script:
Set up wallet files:
wallet-customer.json- Customer wallet (pays fees, receives user token)wallet-mint-sc-policy.json- Admin wallet (provides key_hash parameter)
Update configuration:
Ensure
API_URLandHEADERSare configured in your constants fileModify
assetNameand metadata as desired
Run the parameterized minting script:
Expected Output
Next Steps
This example demonstrates the complete parameterized CIP-68 workflow. For production use:
Add robust error handling for apply-params and transaction failures
Implement parameter validation to ensure correct admin keys
Add transaction monitoring to track minting status on-chain
Create reusable functions for parameter application and script generation
Implement batch operations for multiple asset minting
References
Last updated
Was this helpful?

