Minting NFT via smart contract
Hi devs!
I need to mint a NFT only if the token name equals one input utxo id.
I need to do that to ensure the uniqueness of the NFT, otherwise other people could mint the same token from outside the smart contract.
On Cardano there is the concept of minting script, which is a smart contract that guards the minting/burning of tokens for a particular policy.
How can I accomplish the same on Ergo?
Thank you!
24 Replies
How could an NFT not be unique? Isn't that kinda the point?
Hey, I don't see how this is possible, because the token name is a byte array encoded-UTF8 in the register 4 of the box minting the token. you would need to decode it in the contract and the function does not exists in ergoscript to my knowledge.
That's unusual, let's take a step back: can you guys point me to the technical documentation on how to do an NFT on Ergo please? I probably missed a step there
GitHub
eips/eip-0004.md at master · ergoplatform/eips
Ergo Improvement Proposals. Contribute to ergoplatform/eips development by creating an account on GitHub.
On Ergo we do not have such a thing like Cardano's minting policy. Tokens are minted/burned directly by manipulating the inputs and outputs.
So is it 100% impossible to use them as decentralized access tokens in DeFi?
There are workarounds depending on the use case, I'm not an ErgoScript specialist tho. Probably @Cheese Enthusiast or another contract dev can have better answers.
I do not see why it would be impossible to do this, Ergopad is using stake keys already, I'm sure many other projects are using NFTs for such purposes as well
I am confused on what the question is exactly. Are you talking about the token "name" or the token id? Naming of tokens is a standard, not something you'd use in a smart contract. Token ids are inherent to the protocol, and quite important and useful.
Apologise for the confusion here!
I don't really care about the token name, but I must ensure that the minted token id is equal to one input utxo id and that no one else can create another token with the same id
The way token minting on Ergo works is that the minted token has the id of the first input utxo
So I suppose that works quite well for your usecase
Once the input utxo is spent, nobody else cant mint a token with your id
Oh that's very cool!
So that's probably what I need here, I will test it!
So just curious now: how do multiple NFTs belong to the same collection on Ergo? On cardano you have one piece of the NFT id that stays the same (called PolicyID)
Collections are a standard on Ergo. Honestly I am not too much into NFTs so I don't know how the standard works exactly, but I know that it is not directly within the protocol like policyIds are in Cardano.
Maybe @MGpai would know about collections better
In the current standard, this is not possible
however, this is possible in the new v2 beta standard by anon real
it is complex to understand
but once you understand how boxes work it will make sense
https://github.com/anon-real/eips/blob/master/eip-0034.md#nft-collection-standard
as cheese mentioned, the nft id is same as its input box
this box is known as the issuer box
issuer box is the input
issuance box which contains an NFT is the output
now for a collection there is something called a collection token
if this token is inside of the issuer box before minting
the nft outputted will be considered as part of the collection
now you may ask how does the collection token work
well in fact it is almost exactly as how an NFT is made
the collection token has an input
this again is the collection issuer box
this box should have details regarding the collection in the registers
then the box outputs an issuance box which contains the collection token(s)
the collection token itself has the collection name and collection description
Lilium, my ergohack project takes care of all this complexity
and adds even more validation in the contracts
lilium does this through AVL trees
which @Cheese Enthusiast helped me figure out a while back
alright so the collection token is a special NFT minted before the others that specify details of the collection :think:
yes
and it can be an NFT (quantity of 1) or a token (quantity of n)
That's cool indeed but a little complex for the average NFT creator, I guess lilium cover this gap!
well the average NFT creator won't be deploying entire collections
but yes Lilium is there if they do want to do this
Cardano doesn't agree on this ahah
But that's cool anyway, coming from Cardano I like this Ergo approach!
lmao
well at the end of the day these are standards
so if you have something to propose feel free
what are you trying to do on ergo?
I will surely study more the standard and I will check if some contributions may help!
Thanks for the information btw, I think I can proceed a bit more on my contract now 🤓
What am I trying to do? We are going cross-chain with FluidTokens P2P lending platform!
I think Ergo is a great step for a serious utxo-chains DeFi ecosystem.
Not sure if Ergo has some grants for this, but we are going to dedicate our efforts anyway as we really like it as blockchain
well we have ergo raffle to get funds from the community
we also have hackathons
if you were a month early maybe you could have participated
this lending would have been perfect as it was the hackathon's theme
The timing sucks as always ahah
Too bad, we'll do our best to find the time to deliver on Ergo anyway 🙂
2 related questions:
1) What's the type of the token id? Is it Coll[Byte]?
2) How do I know which tokens are minted/burnt in the tx being validated by my contract?
Tagging @MGpai and @Cheese Enthusiast as super experts 🤓
Sorry didn't see this.
1: Correct
2: The only tokens that can be minted are tokens with the id of
INPUTS(0).id. Tokens are burned by not being present in the outputs of the transaction, you can use filter or fold to check for the burned tokens id in all of the output boxes.Filter has been my final solution, still need to test it but thanks for the important confirmations!