NFT Minting Quickstart w/ Minty 🌿
We’re going to mint an NFT in three steps:
- Generate a .jpeg
- Deploy a minting contract
- Execute the contract to mint
- (bonus) Pin our NFT to IPFS
I’ve adapted the tutorial: Mint an NFT with IPFS by ipfs.io.
We’re going to use some pre-built code to deploy a contract onto a locally running Ethereum network. Then we will execute that contract to mint an NFT and post a jpeg to IPFS.
Minty offers is an all-in-one solution for minting an NFT with IPFS (decentralized) file hosting.
First step is to download directly from the github repo
1$ git clone https://github.com/yusefnapora/minty ; cd minty
Install the NPM dependencies. Add the minty command to your $PATH.
1$ npm install ; npm link
Generate an NFT jpeg
Next, we need an image for our NFT.
In the style CryptoPunks and other generative NFTs, we’re going to make a random jpeg and use it as our NFT image.
To generate a random jpeg I used an online tool to create a random 15x15 jpeg.
Save it in your
minty/ directory. We’ll need it soon.
Run local Ethereum Blockchain
The Minty repo has a built-in script to run an Ethereum blockchain and local IPFS node.
You should see:
1[eth] Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/2...3[ipfs] Daemon is ready
If you do not, try running:
1$ nvm use 16
At this point, this is what you have running on your local machine:
We’re ready to deploy a smart contract.
Deploy Minting Smart Contract
In order to create an NFT, we need to deploy the blueprint for creating the NFT.
In other words, we need to deploy the minting smart contract.
This smart contract (written in solidity) is included in the repo. We just need to deploy it.
In another terminal, run
1$ minty deploy
Aside: If you’ve worked with Serverless, you think of this as doing a
serverless deploy . We are deploying the code that we want to eventually run.
Mint the NFT
Now that we have the local IPFS daemon, local Ethereum network, and smart contract deployed, minting an NFT is simple. We just specify what to tokenize, the name of the NFT, then add a description to tell users what the NFT is for.
1$ minty mint "./output-onlinejpgtools.jpg" --name "Random JPEG #1" --description "A randomly-colored 15x15 square."
Minty will mint the NFT and return some output:
That’s it! Minty executed your smart contract, and your smart contract created the NFT. Your jpeg was also uploaded to your local IPFS node.
So you’ve created your NFT, but it’s only available to other people as long as you have your IPFS node running. If you shut down your computer or you lose your internet connection, then no one else will be able to view your NFT!
To get around this issue, you should pin the image to a pinning service.
Pin the .jpeg
minty deploy command will deploy to a local IPFS node by default.
To use someone else’s node - one that is running 24/7, you can sign up for a pinning service such as Pinata.
You will need to grab an API key from Pinata. Your API key allows Minty to interact with your Pinata account automatically.
Log into Pinata and select API keys from the sidebar menu. Click New Key.
Expand the Pinning Services API drop-down and select all the options under Pins
Pinata will give you an API key, and API secret, and a JWT.
1API Key: 43537d17e888050070862API Secret: 492b24f041b9120cbf8e35a247fb686793231a3d89045f1046a4f5b2d21750823JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiJiZDQ3NjM1Ny1lYWRhLTQ1ZDUtYTVmNS1mM2EwZjRmZGZmYmEiLCJlbWFpbCI6InRhaWxzbm93QHByb3Rvbm1haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInBpbl9wb2xpY3kiOnsicmVnaW9ucyI6W3siaWQiOiJGUkExIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9XSwidmVyc2lvbiI6MX0sIm1mYV9lbmFibGVkIjpmYWxzZX0sImF1dGhlbnRpY2F0aW9uVHlwZSI6InNjb3BlZEtleSIsInNjb3BlZEtleUtleSI6IjQzNTM3ZDE3ZTg4ODA1MDA3MDg2Iiwic2NvcGVkS2V5U2VjcmV0IjoiNDkyYjI0ZjA0MWI5MTIwY2JmOGUzNWEyNDdmYjY4Njc5MzIzMWEzZDg5MDQ1ZjEwNDZhNGY1YjJkMjE3NTA4MiIsImlhdCI6MTYxNjAxMzExNX0.xDV9-cPwDIQInuiB0M--XiJ8dQwwDYMch4gJbc6ogXs
Copy the existing
config/pinata.example.env and replace the value for
1$ cp config/pinata.env.example config/.env
config/.env, add your JWT token to the
PINNING_SERVICE_KEY line between the double quotes “.
Now you can use
minty pin <token_id> to pin it to Pinata.
1$ minty pin 12> 🌿 Pinned all data for token id 1
You can then check your My Files page on Pinata.
…and if it’s there, your NFT jpeg is now pinned! This means that it will persist on IPFS even after you turn off your local IPFS node. Here’s the updated setup:
Pinata will store up to 1GB of NFT images/files for you for free. This image we just uploaded was 239 Bytes, so we have a lot of free space remaining if we wanted to mint some more.
But all done for now. 🏁
In this tutorial, we ran a local Ethereum network with a local IPFS node alongside it, deployed a smart contract to our Ethereum network, generated a random NFT jpeg image, and then used Minty to 1. execute the smart contract to mint the NFT and 2. to post the corresponding jpeg onto our IPFS node. As a bonus, we later pinned our NFT to the pinning service Pinata so that our NFT jpeg would be highly available.