CNFTs with smart contracts

I’m a developer (but noob in the cardano dev ecosystem) and I’m trying to wrap my head around ‘selling nfts on cardano using smart contracts’ to make it trustless. I get the basic dynamics of a smart contract but curious about how to transfer all the jazzy metadata of a whole nft collection into a plutus script.

  1. How do you go by minting a collection of (say)10000 nfts on cardano and selling them using smart contracts??

  2. What exactly is the One-time mint policy mentioned in cardano docs which(as mentioned) can only be possible after the launch of plutus??

Thanks in advance to anyone who responds!

1 Like

I’m also fairly new here and also a developer but learning cardano still. I have recently minted the first NFT for a project my artist friend and I created, having done so without a smart contract just minting using a node and the cardano-cli. When you mint you create a policy script file and from that you generate a Policy ID. That ID then goes in the JSON for the NFT and you use both your payment signing key and policy signing key to sign the transaction before sending it.

The script essentially has rules in it. For example, ours has an “all” that indicates all rules must be met by the policy. Then we have two rules, sig->hash; before->blockheight. Basically means to mint to that policy it must be signed by the signer of the hash, and must be minted before the blockheight…afterwhich it’s considered locked and no other items (nft or coins) can be minted to that policy.

You could treat a policy like a collection (if you are familiar with the opensea or similar format). But again, once the blockheight is reached that you have in your policy script, (and as long as you have the “all”) then no other items will be able to be minted to that policy ID.

As for the selling using smart contracts, I’m in the midst of working on that myself. I’ve created a swap contract on Marlowe but from what I’ve read I will need to do this using Plutus for now as Marlowe will rely on the PAB?? Maybe someone with more info can clarify that point…and I’d love to see a really clear step by step on creating, say a swap contract like I’m working on, and taking it to the blockchain, like the whole process through would be cool (I learn from doing more than reading).

2 Likes

Thank you very much for the detailed explanation!

I was thinking about handling the sale of a collection using smart contracts. We could transfer all the nfts to the script address and wait for a deposit to trigger the observations, then check all the parameter and transfer them to the buyer. But I can’t figure out a way to handle multiple orders. Any idea??

We could ask the buyer for there email and desired amount of tokens. Then generate a new script, fund it with the same number of tokens and wait for a few blocks. If the buyer doesn’t send the funds in time, the tokens get transfered back to the creator’s addr and become available for future buyers. I think this could work well. But would love to have a better, more direct solution.

PS: I too wish we could use Marlowe for it, Plutus is terrifying

Hi there I’d be interested in connecting, I have an artist and project in the works but would need a dev would you be interested in discussing a potential partnership?

So yeah, thought about that also, and presently holding an auction for my artist partner and my first NFT on our site cyphermonks.com, essentially what you are talking about with one offs is what I’m working on developing is a swap contract that only accepts the swap from a specific coded wallet address (the winner of the auction).

As for a more multi approach I have yet to delve into that world. I’m working on a testnet environment in the next day or so to do a few runs and start breaking things and finding where they need fixing :slight_smile:

I’m not sure how my availability would be, although I love the idea of teaming up, I’m an artist also and actively creating our new CypherMonks series by hand with my partner as well as doing all our tech and coding. But I’m totally happy to share finished/working scripts and contracts where appropriate/fitting.

I do have some scripts written in bash for the minting process, still cleaning up that process to make it a little more streamlined (especially in building the tx with correct output when an address holds many NFTs, this part needs more work as I have to do this manually right now).

But hmu regardless, maybe there’s a way we can work something out? I love helping people especially with this stuff, just want to make sure I don’t overpromise! :slight_smile:

I am also trying to write the “automate minting script”. But I’m totally new to linux and bash and got no idea where to start.

It would be great if you could share your script once finished and, for the time being, any resources or docs for getting started with it. Thanks.

PS: your site’s got a great story!

Will do, not at my server now but will be later. My approach involves two systems, which I didn’t see taught anywhere, but should be easy enough to meld together if you wanted to with a single system method.

Basically I don’t want my private keys on a “hot” machine. So I have a cold environment with my signing keys and the latest cardano-cli. I do all my tx signing on that machine. The hot machine is a live 24/7 node and has none of my keys, just used to build the tx and then submit the signed tx.

So the process is:

  1. Upload the NFT (upload to IPFS via Pinata.cloud or similar…they have a 1GB of free pinning)
  2. Prepare the NFT JSON file with details/description/name and IPFS hash taken from pinata after upload.
  3. On the Hot server get the blockchain tip (block number) then add to that for the time you want before the policy ID for that NFT or set of NFTs will be locked, meaning no more minting. So if you had all your NFTs ready to mint and think it may take a few hours, just add a few hours…I believe about 3600 = 1 hour, so you add that figure to the block tip number you generated.
  4. Update your policy script with that figure in the section for “before” and make sure the hash for the “sig” section is correct and matches your generated policy hash.
  5. Generate your policy ID from that script.
  6. Update your NFT JSON file with the policy ID
  7. Copy your Policy Script, Policy ID, and JSON to your hot server (or just keep templates there and update with each minting from the ID generated on your cold server)
  8. Run the build tx script
  9. Copy it to your cold server and sign it
  10. Copy the signed tx back to your hot server and submit it…done.

I’ll post a more thorough outline with the scripts I created later on, in the meantime check out this youtube vid, he does a good job explaining/walking through it and has supporting docs as well…which I found helpful in creating my own.

One of the tricky parts as I said was in the building tx phase, after an NFT had been minted, making sure my output tx was correct in including the NFTs on that address in where they should be sent in the output. I ran into a weird error just running my script and had to manually put the output into it (rather than it automatically getting the output), so I have to fix that part still.

1 Like

Thanks a lot mate!

1 Like

okay, my instructions are incomplete still on github, but I put the scripts there and am working on finishing up the instructions…cos I also need them for when I forget next time lol. Here it is, again may be a bit buggy still:

2 Likes

Haha, Thanks!

You got it! I’ll get them updated soon, working on some smart contract exercises for now :slight_smile:

1 Like

Okay sounds good are you on Discord or telegram I can dm you.

@artistulla any plan to use Plutus script to mint NFT? (which I think is a more formal way to mint NFT). I am stuck in how to deploy the plutus scripts on testnet & mainnet. Can’t find a good tutorial on this. I can so far find tutorials on how to do it on the simulator only. Would be great if somebody can share his experience.

There are exercises and solutions for minting using Plutus at https://github.com/input-output-hk/Alonzo-testnet/blob/main/Alonzo-exercises/alonzo-purple/5_Alonzo-purple-exercise-5.md. The code will work on mainnet, testnet, and Alonzo purple now.

3 Likes

thanks @bwbush … where can we find the solutions (code, explained answers, anything) to the questions & exercises on this page? :pray:

1 Like

Yeah there are only instructions but no solutions in there… :frowning:

Do you know about the one-time mint policy mentioned in the Cardano Docs??
https://docs.cardano.org/native-tokens/learn

" One-time minting policy

In a one-time mint policy, the complete set of tokens of a given asset group is minted by one specific transaction. This means that no more tokens in that particular asset group will ever be minted. This type of policy needs Plutus smart contracts to be implemented."

Please provide any extra info or resources related to this if you have any.

@COSDpool and @theachyutraj: Sorry, I should have checked that they populated the solutions folder! Here are a couple of resources:

  1. Lars’s lobster token minting, which includes NFTs and fungible tokens. The lobster-naming game is running on mainnet.
  2. Solution to Plutus Pioneer exercise 5, which might need minor adjustments to run on mainnet or testnet.
  3. Plutus use case for a one-time currency (an NFT), which is likely to work on testnet and mainnet, but I haven’t tried it myself.

@Tam_Edward, Version 1.29.0 of cardano-cli will deploy a Plutus script, using --tx-in-script-file. See here for a step-by-step example.

5 Likes