User Update Example
This guide provides a complete Deno implementation for user-driven CIP-68 NFT metadata updates using spend validators, fee payments, and token ownership verification with the Anvil API.
Full Code Example
Implementation Overview
This example demonstrates user-driven metadata updates where token holders can update their own NFT metadata by:
Proving ownership of the user token (222)
Paying a 1 ADA fee to the admin
Updating limited metadata fields (e.g., nickname)
Following the spend validator's authorization rules
Prerequisites
This guide assumes you have completed the Minting Example and have:
Existing CIP-68 tokens - Reference and user tokens from a successful mint
User token ownership - The user token (222) must be in the customer's wallet
Reference token location - Current UTXO of the reference token at the script address
Blockfrost API access - For dynamic UTXO discovery
Understanding of user updates - Review update logic for validation details
Step-by-Step Implementation
Let's build a user-driven CIP-68 metadata update script step by step. Each section explains the concept and shows the corresponding code.
Step 1: Setup and Configuration
Create update file with the required imports and configuration:
Key differences from admin updates:
Customer wallet signs the transaction (not admin)
Admin address receives the 1 ADA fee payment
Blockfrost integration for dynamic UTXO discovery
Asset name must match the originally minted token
Step 2: Apply Parameters and Find UTXOs
Apply parameters to the blueprint and locate the required UTXOs:
What's happening here:
Reference token discovery: Finds the current reference token UTXO at the script address
User token discovery: Locates the user token in the customer's wallet (proves ownership)
UTXO string format: Gets the hex-encoded UTXO string needed for
requiredInputsValidation: Ensures both tokens exist before proceeding
Step 3: Build the User Update Transaction
Now we build the spend transaction with user authorization:
Key redeemer components:
nickname: The updated value in hex format (limited user permission)
fee_output_index: Points to the 1 ADA fee payment output
output_ref_user_token: References the user token for ownership verification
Step 4: Define Transaction Outputs
Create the outputs for the updated reference token and fee payment:
Critical output requirements:
Output 0: Updated reference token with new metadata at script address
Output 1: Exactly 1 ADA fee payment to admin address
Datum preservation: Original asset name must be preserved
User token input: Must be included via
requiredInputsfor ownership proof
Step 5: Build, Sign, and Submit Transaction
Build and submit the user update transaction:
What's happening here:
Customer signature: Only the customer signs (proves they own the user token)
No admin signature: Admin authorization comes from fee payment, not signature
Validation on-chain: Smart contract validates ownership and fee payment
Running the Example
Prerequisites Setup
Complete the minting example first to have CIP-68 tokens available
Set up environment variables:
Update configuration:
Set
assetNameto match your minted tokenModify
nicknameto your desired update valueEnsure wallet files are properly configured
Run the user update script:
Expected Output
User vs Admin Updates
This user update approach differs from admin updates in three key ways:
Authorization
Token ownership + 1 ADA fee
Admin signature only
Permissions
Limited fields (e.g., nickname)
Full metadata access
Cost
1 ADA fee to admin
Free for admin
The economic barrier prevents spam while giving users control over their metadata.
Troubleshooting
Common Validation Failures
If your transaction fails validation, check these common issues:
user_token_quantity != 1- User token not included in transaction inputslovelace_paid != 1000000- Fee amount is not exactly 1 ADA!is_paid_to_admin- Fee payment sent to wrong addresscurrent_datum != expected_datum- Attempting to update restricted metadata fields
Key Requirements
Include user token in
requiredInputsfor ownership proofPay exactly 1 ADA (1,000,000 lovelace) to admin address
Update only permitted fields as defined by the smart contract
Track UTXO locations dynamically (tokens move with each update)
Next Steps
You now have a complete user-driven update implementation. For production applications, consider:
Batch Updates: Multiple metadata fields in one transaction
Update History: Track metadata changes for audit trails
Fee Estimation: Display costs before transaction submission
User Interface: Build a frontend for non-technical users
References
Update Logic Guide - Deep dive into Aiken implementation
Admin Update Example - Admin-driven updates
CIP-68 Specification - Official standard
Working Implementation - Complete code
Last updated
Was this helpful?

