<p>There are onchain validator scripts available like this one, which describe nicely how it can be done.</p>
<p><a href="https://github.com/Berry-Pool/nft-plutus/blob/main/src/cardano/nft/onchain.hs" rel="nofollow noreferrer">nft-plutus by Berry Pool</a></p>

CC BY-SA 4.0
2022-05-26T18:35:22.340Z
2022-05-26T18:35:22.340Z
Will
<p>The way that my vending machine does it is that I store all of the total NFT collection in a MongoDB. Then, when my script sees a sale UTXO come into a wallet, it queries the MongoDB for any NFT that is still 'available' and pulls them all down into an array. I then shuffle the array and mint the one in the [0] spot. Finally, I mark the NFT as sold in MongoDB.</p>

CC BY-SA 4.0
2022-01-26T06:55:10.117Z
This question is about plutus, not offchain solutions.
eddex
CC BY-SA 4.0
2021-12-27T00:43:26.667Z
2021-12-27T00:43:26.667Z
Tygar Pool
<p>If I have a wallet that currently stores x amount of NFT's and I make a validator script that provides one NFT from that wallet in exchange for ADA what would I call to make sure 1 unique NFT goes out to each caller of the said validator script? Specifically how would the validator script know which NFT to give out? Is there a way to sort out metadata of NFT's using script context and pick the next NFT to send out by its number order?</p>

<plutus><nft>
How to create an NFT collection sale validator script
# How to create an NFT collection sale validator script

(Asked by: username_0 on 2021-12-22)

If I have a wallet that currently stores x amount of NFT's and I make a validator script that provides one NFT from that wallet in exchange for ADA what would I call to make sure 1 unique NFT goes out to each caller of the said validator script? Specifically how would the validator script know which NFT to give out? Is there a way to sort out metadata of NFT's using script context and pick the next NFT to send out by its number order?

**Tags:** plutus, nft

---

## 2 answers

### Answer by username_1 on 2022-05-26. Score: 0 | Accepted answer

There are onchain validator scripts available like this one, which describe nicely how it can be done.

[nft-plutus by Berry Pool](https://github.com/Berry-Pool/nft-plutus/blob/main/src/cardano/nft/onchain.hs)


---

### Answer by username_2 on 2021-12-27. Score: -2

The way that my vending machine does it is that I store all of the total NFT collection in a MongoDB. Then, when my script sees a sale UTXO come into a wallet, it queries the MongoDB for any NFT that is still 'available' and pulls them all down into an array. I then shuffle the array and mint the one in the [0] spot. Finally, I mark the NFT as sold in MongoDB.

> **Comments:**
> **username_3**: This question is about plutus, not offchain solutions.  

---

