Update Logic

Understanding the smart contract - How to update CIP-68 NFT metadata on Cardano using Aiken spend validators. Deep dive into user vs admin update paths, fee mechanisms, and validation logic.

You've successfully minted CIP-68 tokens and now want to understand how metadata updates work through the spend validator!

circle-info

Prerequisites: This guide assumes you understand CIP-68 minting logic and have successfully minted tokens using the minting example. The spend validator builds upon the mint validator's foundation.

Ready to implement? Skip to the admin update example or user update example and return here when you want to understand the underlying validation logic.

Conceptual Foundation

What the Spend Validator Does

While the mint validator creates CIP-68 token pairs, the spend validator enables metadata updates by controlling how reference tokens can be spent and recreated.

Core Responsibilities:

  • βœ… Authorizes Updates: Two paths - admin signature OR user token ownership + fee

  • βœ… Preserves Token Integrity: Reference tokens must stay at smart contract address

  • βœ… Maintains CIP-68 Compliance: Updated metadata follows proper structure

The Update Process

Every CIP-68 metadata update follows this sequence:

  1. Spend Existing: Consume the current reference token UTXO

  2. Validate Authority: Check authorization (admin OR user + fee)

  3. Transform Metadata: Apply authorized changes to the datum

  4. Recreate Token: Send updated reference token back to smart contract

circle-check

Two Authorization Paths

πŸ‘€ User Updates:

  • Must own user token (222) and include it as transaction input

  • Must pay exactly 1 ADA fee to admin address

  • Can only update specific fields (e.g., "nickname")

  • Other metadata fields are preserved

πŸ‘‘ Admin Updates:

  • Admin must sign the transaction with their private key

  • No fee payment required

  • Can update any metadata fields, can modify entire metadata structure and version

Validation Flow Overview

The diagram below shows how the spend validator processes both authorization paths:

spinner

Authorization Logic Deep Dive

The spend validator implements two distinct authorization paths, each with specific validation requirements:

πŸ‘€ User Update Path

Users prove ownership and pay fees to update limited metadata fields:

Requirements: User token ownership + 1 ADA fee + limited field updates

πŸ‘‘ Admin Update Path

Admins use signature authorization for full metadata control:

Requirements: Admin signature only + full metadata permissions

Core Validation (Both Paths)

All updates must also pass these fundamental checks:

  • Address Preservation: input.address == output.address

  • Token Integrity: input.value == output.value (same token, updated metadata)

  • Datum Structure: Valid CIP-68 metadata format

Implementation Examples

User Update Transaction Structure

Admin Update Transaction Structure

Production Considerations

Security Model

  • User Updates: Token ownership + 1 ADA fee + limited permissions

  • Admin Updates: Signature authorization + full permissions

  • Token Integrity: Reference tokens locked at smart contract address

  • Audit Trail: All metadata changes recorded on-chain

Common Errors

User Update Failures:

  • user_token_quantity != 1 - User doesn't own the token

  • lovelace_paid != 1000000 - Incorrect fee amount

  • current_datum != expected_datum - Unauthorized metadata field update

Admin Update Failures:

  • !list.has(extra_signatories, signer) - Missing admin signature

  • input.address != output.address - Address preservation failed

Core Validation Failures:

  • datum not Cip68Metadata - Invalid metadata structure

  • input.value != output.value - Token integrity violated

Next Steps

User Update Examplechevron-rightAdmin Update Examplechevron-right

Technical References

Last updated

Was this helpful?