What happens when you mint an NFT?
So you’ve decided you want a CryptoKitty, a Bored Ape, maybe even a Punk! The JPEG is cool, but what actually happens under the hood? Well the mechanics underlying your NFT can actually be very different for each project.
In this series, we’ll start off with a general TLDR for how most NFT projects work (scroll down if the anticipation is killing you). They follow similar principles which can be interesting if you want only a surface level understanding.
For those who need to understand the fundamentals of a thing, we will next dive deeper. The only way to understand the first principles of an NFT is to look at the smart contract that controls it. Diving into projects running on the Ethereum network, we will break apart the Solidity code of each smart contract. They are surprisingly easy to understand. Short and simple contracts are able to implement powerful concepts.
The series will progress from the earliest projects like CryptoPunks and Mooncats, through the NFT721 standard, into the PFP era led by Bored Ape Yacht Club, and into generative works like ArtBlocks.
This is an investigation I’ve done myself as research for building my own NFT collections. I’ve tried to learn the pros and cons of various techniques to determine the best contract construction. If you’re building your own project, or just want to understand the details of NFTs you’re spending thousands of dollars on for your own collection, I hope this exploration will help inform you.
I found it surprisingly hard to find any information on how these contracts are broken down, so in the spirit of open and decentralized information, I can pass the research on. The sooner we can understand these building blocks, the sooner we can use them to build even higher.
An amazing property of this NFT era is that the entire blockchain is public and free to read. This is what gives us the ability to crack open the smart contract on any NFT and learn all about it. If you follow along, you’ll also learn the techniques for analyzing these contracts yourself for any future NFTs you want to investigate yourself.
Smallest NFT TLDR that still gives you the important insights
Let’s start off with Bored Ape Yacht Club (BAYC) to highlight the basics. We’ll follow up in the next post with a deeper dive into their smart contract.
At the highest level, a project like BAYC has a single Solidity contract that represents the entire collection. Here it is!
The team at BAYC wrote this contract, then published it onto the Ethereum blockchain.
So what happens when you mint? It looks like this:
Each person will use their Ethereum account (through a wallet like MetaMask) to call a mint function on the project’s smart contract. Specifically for BAYC, you call a function called mintApe on that contract. Here’s what the function looks like using Etherscan to explore the functions we have available from the contract.
The mintApe function will no longer work, because the project minted all 10,000 NFTs long ago (long ago… in NFT terms, this was actually only a few months ago).
Assuming you could call mintApe, what would happen? It’s not very complicated. We can even look at code:
_holderTokens[to].add(tokenId);
emit Transfer(address(0), to, tokenId);
You need only a simplistic understand of how programming works to see what’s happening here. In the first line, to
is your Ethereum account address. It gets stored in a map called _holderTokens
. Your address points to the tokenId
(your ape’s Id), which you minted. That’s all that gets saved. It’s all stored on the contract. That’s almost it.
I said almost because there’s one more imporant thing that happens. The contract will send an event out to the Ethereum network with your address and the token you purchased. Now that’s really it.
So when you mint, does anything actually get sent to you or your wallet? No! It feels counter intuitive because of the way applications show us our NFTs. It feels almost like we do physically hold them in our wallets. But this follows the same principles of how the blockchain itself works. There’s just the blockchain. A big ledger. We’re recording line items in a registry that says who owns what. The only record of your NFT ownership is the entery in the BYAC smart contract referencing your Ethereum account address to the NFT token ID and a fired event. Amazing!
It is also interesting to think about how an aggregator like OpenSea can show the NFTs which have been recorded against your Ethereum account address. There is no way they could scan all smart contracts of all projects ever created. Also, they would need to constantly be scanning for any transfers of ownship. Instead, they watch all events and keep their own database of ownership.
We’ve only scratched the surface of what an NFT is. What about the JPEG? Where is it stored? How is it linked to your address or token ID? We’ll need to explore further. This is where things start to deviate between projects. Some may store your image on centrally controlled systems like AWS, others using decentralized external storage like IPFS, while other try to remain pure and store it directly in the smart contract itself. We’ll continue on with our BAYC exploration next to see how they do it.
OK, the real NFT TLDR
To wrap it up, what is an NFT then?
Recording of your Ethereum address with your NFT’s token ID in the smart contract of the NFT project.
An event fired by the project’s Smart Contract.
That’s it!
Done for now, until we dive deeper.