Admin Update Example

This guide provides a complete Deno implementation for updating CIP-68 NFT metadata using spend validators with parameterized smart contracts and the Anvil API.

circle-info

Want to understand the smart contract validation logic first? Check out the Update Logic Guide to learn how the contract ensures proper authorization for metadata updates. Otherwise, you can dive right into the implementation below!

Full Code Example

circle-info

Want to see the complete code first? Check out the full working implementationarrow-up-right on GitHub, then come back here for the step-by-step breakdown.

Implementation Overview

This example demonstrates:

  • Spending existing reference tokens for metadata updates

  • Using spend validators with proper redeemer structures

  • Admin authorization patterns for metadata changes

  • Complete end-to-end update workflow

Prerequisites

This guide assumes you have completed the Minting Example. Additionally, you need:

  1. Existing CIP-68 tokens - Reference and user tokens from a successful mint

  2. Current reference token UTXO - Transaction hash and output index where the reference token currently resides

  3. Understanding of spend validators - Updates consume and recreate reference tokens with new metadata

Step-by-Step Implementation

Let's build a CIP-68 metadata update script step by step. Each section will explain the concept and show the corresponding code.

Step 1: Setup and Configuration

Using the same setup from the minting example:

Key difference from minting:

  • TX_HASH and TX_OUTPUT_INDEX specify which existing reference token to update

Step 2: Apply Parameters to Blueprint

The apply-params process is identical to the minting example:

Result: Same parameterized script and address as your original mint

Step 3: Build the Update Transaction

Now we build the spend transaction that will update the metadata. The key insight is that we spend the existing reference token and recreate it with new metadata:

What's happening here:

  • Script interactions: Tells the smart contract we're spending a UTXO locked at the contract address

  • OutputRef: Specifies exactly which reference token UTXO we want to update

  • Redeemer: Contains the authorization data - "AdminUpdate" means admin signature is required

Step 4: Define the Updated Output

We need to send the reference token back to the smart contract with updated metadata:

What's happening here:

  • Output: The reference token is sent back to the smart contract with updated metadata

  • Datum: Contains the new metadata following CIP-68 specification

  • Required signers: Admin must sign the transaction for authorization

  • Preloaded scripts: Include the parameterized script for validation

Step 5: Build and Submit Transaction

Now we build, sign, and submit the transaction:

What's happening here:

  • The tx-builder validates our spend transaction and creates a Cardano transaction

  • We sign with the admin's private key (required for "AdminUpdate" authorization)

  • The transaction is submitted to the Cardano network

  • On success, we get back a transaction hash for tracking

Running the Example

  1. Find your reference token UTXO:

    • Use CardanoScan to search for your policy ID from the mint

    • Locate the reference token (label 100) at the smart contract address

    • Update TX_HASH and TX_OUTPUT_INDEX in your script

  2. Modify the metadata in the datum.value.metadata section as desired

  3. Run the update script:

Expected Output

Understanding the Update Process

Spend Validator Logic

The CIP-68 update process uses a spend validator that:

  1. Validates Authorization: Checks that the admin has signed the transaction

  2. Preserves Token Integrity: Ensures the reference token stays at the smart contract

  3. Allows Metadata Changes: Permits updates to the inline datum containing metadata

  4. Maintains CIP-68 Compliance: Enforces proper metadata structure and versioning

Authorization Patterns

Admin Update (shown in this example):

  • Requires admin signature

  • No fee payment needed

  • Full metadata update permissions

User Update (alternative pattern):

  • Requires user token ownership proof

  • Fee payment to admin

  • Limited metadata update permissions

Transaction Flow

  1. Input: Spend the existing reference token UTXO

  2. Validation: Smart contract validates admin signature

  3. Output: Create new reference token UTXO with updated metadata

  4. Result: Metadata is updated while preserving token integrity

Key Requirements

  • Track UTXO locations: Reference tokens move with each update

  • Use same script hash: From your original mint parameterization

  • Admin signature required: Only the minting admin can perform admin updates

Next Steps

This example demonstrates the complete CIP-68 admin update workflow. For production use:

  1. Add UTXO discovery to automatically find current reference token locations

  2. Implement user updates with fee payment and user token validation

  3. Add batch operations for updating multiple tokens

  4. Create metadata validation to ensure proper format and constraints

  5. Implement update history tracking for audit trails

References

Last updated

Was this helpful?