Native Script Minting
A Deno-based script for minting CIP-68 assets on the Cardano blockchain using the Anvil API. This guide provides a complete example for building, signing, and submitting a transaction to mint a CIP-68
Quick-Start Example
This streamlined tutorial shows how to mint a CIP-68 NFT on Cardano using Deno + Fetch and the Anvil API.
We'll:
Load wallets (Customer, Policy, Metadata Manager)
Create a native script using our Native Script utilities
Build a mint payload that creates both tokens (
100+222) in the same transaction.Call
transactions/buildSign with the Policy & Customer (
skeys) keys. Customer in the backend for simplicity.Submit the transaction
Verify on-chain that the assets are minted:
The reference token is sent to the metadata manager wallet
The user token is sent to the customer wallet
Prerequisites
Three Wallets – You'll need three wallets with these fields:
Customer Wallet: Pays fees, receives user token (label 222)
base_address_preprod: Testnet address (addr_test1...)skey: Signing key (ed25519e_sk1...)
Policy Wallet: Controls minting policy
base_address_preprod: Testnet address (addr_test1...)skey: Signing key (ed25519e_sk1...)
Metadata Manager Wallet: Receives reference token (label 100)
base_address_preprod: Testnet address (addr_test1...)skey: Signing key (optional for this script. Used when updating metadata)
Create wallets with our Wallet CLI. Ensure customer wallet has ADA for fees.
Anvil API Key – A valid Anvil API key. See Authentication.
Utility Helpers – Import helpers from the utilities-functions guide to keep this file short.
Project Structure
For the absolute minimum setup, you only need:
Quick-Start Script
Utility Files Reference
You'll need to create the utility files. See the Utility Functions documentation for detailed API endpoint information and examples.
The utility files provide these key functions:
timeToSlot(date)- Converts timestamps to Cardano slotsgetKeyhash(address)- Extracts payment key hash from addressescreateNativeScript(keyHash, ttl)- Creates time-locked native scriptsAPI configuration - Anvil API endpoints and headers
💡 Tip: The anvil-api-examples repository contains the most up-to-date utility functions and is the recommended source.
Running the Script
Troubleshooting
Common Issues
Error: "Module not found"
Check that your import paths match your project structure
Ensure
utils/shared.tsandutils/constant.tsexist
Error: "Failed to get key hash for address"
Verify your wallet addresses are valid testnet addresses
Check that wallet files contain proper JSON format
Ensure addresses start with
addr_test1
Error: "API call failed: Input validation failed"
Usually means wallet address parsing failed
Double-check wallet file format and addresses
Error: "Unable to build tx"
Ensure customer wallet has sufficient ADA for fees
Check that API key is valid
Verify network connectivity
CIP-68 Specific Notes
Two tokens are minted in the same transaction:
Reference token (label 100) - Contains metadata, sent to metadata manager wallet
User token (label 222) - The actual NFT, sent to customer wallet
Full Example Script
For complete, fully-annotated examples see the examples repository:
Last updated
Was this helpful?

