I have a question but I cannot find a concrete answer for that. I have a smart contract developed in Plutus for managing locking and withdraw of Tokens/NFTs. I'm wondering if I can validate some metadata of my NFT onchain, in my validator script.

For example, imagining this NFT: https://pool.pm/asset16tkxq9yrk6lmkwld6vnz5m8f6j54gj376jy2xx

The metadata contains: Artist, Artist Website, Id, Rarity and so on; Can I get the information about the metadata onchain on my validation script? so I can verify an specific word contained on this attributes?

Thank you so much.


1 Answer 1


If the NFT was minted using a transaction with metadata (cardano-cli), then the Plutus script won't be able to access this information. This is because you can only feed UTxOs to Plutus validator scripts. UTxOs don't contain the data stored on the ledger.

If you are in this situation, I would solve your problem by getting the metadata of the NFT from the ledger (using a service like Blockfrost) and validating it BEFORE feeding the UTxO to the validator script. This way, if metadata doesn't match, then there's no point in continuing with the execution of the Plutus script.

On the contrary, if the NFT was minted using a Plutus minting policy, as per this tweet, you have the ability to store this information in the UTxOs, using TxWitness field, as part of the datum hash.

  • If by "BEFORE" you mean in off chain code, than I don't think this is a right approach as advarsery can easily bypass that and send invalid/different metadata to an chain code. Second proposal will work, if you store datum or datum hash in validator script utxos. If the number of NFTs is big (lets say 10_000), than this will require creation of 10_000 utxos which is costly. Currently every utxo has to have at least 1 ada so in this case that would cost 10_000ada just to be able to verify the metadata on chain.
    – akegalj
    Sep 15, 2022 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.