An NFT is a transaction recorded on a blockchain that attests the ownership of a unique object, linked via metadata to resources, usually images or video.
Okay, this definition is so general that it doesn't explain anything when you read it like this.
Photo by Ananthu Ganesh on Unsplash
Imagine you are at the supermarket, and you get a coupon or stamp for every $30 you spend. You are a loyal customer and have 20 half-dollar coupons.
Now imagine that as you rush out the doors with your coupons in hand, a middle-aged lady bumps into you, and your 20 coupons fall out, mingling with the lady's ones.
If we think of coupons as tokens, they are fungible: you can exchange them for each other. Each has the same value and characteristics as the other.
If you dropped your house keys instead of coupons, that was different.
Although visually similar, each key differs from the other, and you could not interchange them with the lady. If we think of keys as tokens, these are non-fungible tokens.
> Student: So, are house keys NFTs? > Guru: No, because they do not "live" on the blockchain. > Student: Right, and how does the blockchain work?
The good news is that it is optional to know in detail how a blockchain works to develop an NFT. We need to know some basic information. Let's see it.
The blockchain (at its base) is a distributed data ledger, i.e., we can imagine it as a database or data storage in which transactions, i.e., changes in the state of the blockchain, are written.
The addition of data is done through consensus mechanisms because most of the network nodes validate the transaction.
The current block's hash is calculated, then inserted as a reference within the next block, thus concatenating the two blocks. As new blocks are added, the chain grows.
> student: okay, but you still need to tell me how to develop an NFT. > guru: Easy, you can't run before you know how to walk.
In the Bitcoin blockchain, transactions essentially contain currency transfers from one account to another. Still, in 2015, thanks to the work of Vitalik Buterin, Ethereum was born.
This new blockchain allows code to run on it. This code, these programs that run on the blockchain, are called smart contracts.
Each node on the Ethereum network implements a system called the Ethereum Virtual Machine (EVM), a virtual machine capable of executing smart contracts code, using the local copy of the blockchain to read and write information, and possibly interacting with other smart contracts.
NFTs are a particular type of smart contract that implement a specific standard. This standard is ERC-721, which defines an interface to be implemented by the smart contract.
This interface has functions for determining the ownership of an NFT and functions for transferring it.
Then there are functions to obtain the name and symbol of the NFT.
An essential function is tokenURI, which defines a URI for each of the tokens managed by the contract.
This URI must point to a JSON file with a structure like the one defined in the figure. The standard defines the first three fields. The attributes are an extension added by the OpenSea marketplace and then became very common.
The image attribute points to the actual image.
Typically, users interact with a smart contract through a dApp (decentralized application), which interacts with the smart contracts deployed on the blockchain.
Usually, the dApp takes care of getting the user connected through its wallet. At this point, it allows the user to perform minting, that is: generating a new NFT from the smart contract.
The contract will write a transaction on the blockchain, generating a new token with its associated token id.
At this point, we can write the initial definition again, which I hope has become more evident:
An NFT is a transaction recorded on a blockchain that attests the ownership of a unique object, linked via metadata to resources, usually images or video.
> student: now I understand, but in practice how should I develop an NFT?
To develop the smart contract code, you use a programming language called Solidity.
The ERC-721 interface has already been implemented for us by Openzeppelin, a company that has written many open-source smart contracts.
Some frameworks and tools help us develop the smart contract of an NFT, test it, deploy it on the blockchain, interact with the deployed contract, and finally create a dApp for users to interact with it.
Among the most popular are truffle and hardhat.
To develop an NFT, you should follow these steps:
> Student: but how do I connect to a blockchain node?
Connecting to a blockchain node is a challenging task.
But first, let's see how a node works. Each blockchain node consists of essential parts:
When a user wants to interact with the blockchain, he must connect to a node, and he does so by calling the APIs that each node exposes.
To do so, he needs to know the Internet address of this API.
Moreover, these APIs are not the classic REST APIs we are used to using every day but are "slightly" more complex. For two reasons:
1. the content of the messages, which follow a standard, are encoded in hexadecimal
2. You must sign most of the messages with your private key.
You should use a ready-made library to implement calls to a blockchain node. There are some for almost every language.
> Student: why can't I launch a blockchain node by myself?
In the end, it's just a program running on a server.
> Guru: Running a blockchain node on your pc or server is not trivial.
Server space in the hard disk (about a terabyte currently), a lot of RAM, CPU, and download internet bandwidth. You also need to synchronize all existing blockchain data before you
can start receiving calls to "run smart contracts."
Fortunately, there are so-called providers, i.e., services that expose the same API as the blockchain nodes but are more reliable and dedicated to these operations. The most famous providers are certainly Infura and Alchemy.
So, when you want to deploy the NFT's smart contract on the blockchain, you must connect to a provider and perform a "special" contract creation transaction.
When the contract gets deployed on the blockchain, it assigns an address to it.
The blockchain contract address is unique and must be used to execute the various transactions that the smart contract exposes: for example, the mint or transfer of an NFT.
We have given an overview of what it takes to create an NFT. We have barely scratched the surface of this world, and in this article, there was no way to get into the depths of development details, but stay tuned. I will post more implementation-specific material as soon as possible.
In the meantime, if you want to learn how to develop an NFT or smart contract, feel free to contact me.
Thanks, and until next time
Find out if MentorCruise is a good fit for you – fast, free, and no pressure.
Tell us about your goals
See how mentorship compares to other options
Preview your first month