<p>If the NFT was minted using a transaction with metadata (<code>cardano-cli</code>), 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.</p>
<p>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 <a href="https://docs.blockfrost.io/#tag/Cardano-Metadata" rel="nofollow noreferrer">Blockfrost</a>) 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.</p>
<p>On the contrary, if the NFT was minted using a Plutus minting policy, as per <a href="https://twitter.com/dcspark_io/status/1420927974480637953" rel="nofollow noreferrer">this tweet</a>, you have the ability to store this information in the UTxOs, using <code>TxWitness</code> field, as part of the datum hash.</p>

CC BY-SA 4.0
2022-09-15T16:50:04.713Z
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
CC BY-SA 4.0
2022-05-23T23:20:24.493Z
2022-05-23T23:20:24.493Z
Falcon Stakepool
<p>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.</p>
<p>For example, imagining this NFT: <a href="https://pool.pm/asset16tkxq9yrk6lmkwld6vnz5m8f6j54gj376jy2xx" rel="nofollow noreferrer">https://pool.pm/asset16tkxq9yrk6lmkwld6vnz5m8f6j54gj376jy2xx</a></p>
<p>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?</p>
<p>Thank you so much.</p>

CC BY-SA 4.0
2022-09-15T18:51:29.730Z
There is a solution proposed in this question https://cardano.stackexchange.com/q/4609/5589 . As proposed, you can send another token to the validator script and set its datum to metadata.

Another option is proposed https://cardano.stackexchange.com/questions/4609/how-to-retrieve-the-datum-added-with-the-option-tx-out-datum-embed-file-from-th#comment4987_4609
akegalj
<plutus><nft><metadata><script>
Plutus Script Validation Metadata
# Plutus Script Validation Metadata

(Asked by: username_0 on 2022-05-19)

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.

**Tags:** plutus, nft, metadata, script
> **Comments:**
> **username_1**: There is a solution proposed in this question https://cardano.stackexchange.com/q/4609/5589 . As proposed, you can send another token to the validator script and set its datum to metadata.  Another option is proposed https://cardano.stackexchange.com/questions/4609/how-to-retrieve-the-datum-added-with-the-option-tx-out-datum-embed-file-from-th#comment4987_4609  

---

## 1 answers

### Answer by username_2 on 2022-05-23. Score: 2 | Accepted answer

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](https://docs.blockfrost.io/#tag/Cardano-Metadata)) 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](https://twitter.com/dcspark_io/status/1420927974480637953), you have the ability to store this information in the UTxOs, using `TxWitness` field, as part of the datum hash.

> **Comments:**
> **username_1**: 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.  

---

