I want to create a NFT collection in which the creator does not have to mint the NFT's but the consumer does through a smart contract that they interact with. Would this be possible to do while sill keeping the same policy ID for each NFT or is that only possible by pre-minting the NFT's and sending them to a storing wallet.
Yes, you can do that.
An example could be to use a sequence number in a validator script (smart contract) in conjuction with a policy.
- Validator script (smart contract) should manage the sequence number. For this, you can use the datum. Every time you mint a NFT, check that datum has increased (+1).
- Policy can be the same for all tokens. You can append to your token name, the sequence number (here you can find a function to convert integer to bytestring)
Just make sure, to use a dummy NFT in your validator script:
- To identify the right UTXO every time you mint
- To validate from the policy script that it's included in the transaction.
Here is a good explanation for that.
@georgeos answer is correct
I'd like to point out another way you could implement this:
You could use the consumer's UTxO as an input into the Token Name (it's common to use it as an parameter of the script to affect the policy name). Then you don't need to track state on a datum.
I'll mention, these methods will make the tokens non-fungible and unique, but if anyone can mint the NFTs they might not be particularly scarce--something to keep in mind. That being said, I think there are still some interesting uses for these patterns. And there would be additional ways to make the tokens scarce with time constraints, etc.