ERC721: Digital Collectibles on Ethereum
What is ERC721?
ERC721 is a technical standard that defines a common set of rules that allows us create tokens that are non-fungible i.e. Non Fungible Tokens or NFTs on the blockchain. Each ERC721 token or NFT represents a unique item and can't be swapped one-for-one with another token.
How Do ERC721 Tokens Work?
When you create an ERC721 token, you're actually writing something called a "smart contract." This smart contract tells the blockchain how to handle your unique digital item. It keeps track of who owns each token and lets people buy, sell, and trade them.
How to Create Your Own ERC721 Token
To create your own ERC721 token, you'll have to craft a smart contract using Solidity, a programming language designed for Ethereum. But fear not, there are tools like OpenZeppelin that abstract the process and make it easier for you.
Here's a simple example of what your smart contract might look like:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyNFT is ERC721, ERC721Burnable, Ownable {
constructor(address initialOwner)
ERC721("MyNFT", "MNFT")
Ownable(initialOwner)
{}
function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
}
Metadata and IPFS
To create an NFT, you will need to create a metadata for it. An NFT metadata is data that provides information about an NFT’s essential properties. It describes the NFT’s name, description, and other important details.
Before writing the NFT contract, you will need to host your artwork and create a metadata file. This can be done using IPFS (InterPlanetary File System), IPFS is a peer-to-peer file storage distributed system. NFT.Storage is a platform that allows you upload your files to IPFS.
Minting and Burning NFTs
To mint an NFT, you would call the function safeMint
or mint
specifying the recipient's address and a unique token ID. For burning NFTs, you can use a contract like OpenZeppelin's ERC721Burnable.sol , which adds the ability to permanently remove NFTs from circulation, with only the owner having the ability to invoke it.
Here is the link to an NFT I created
Wrapping Up
The ERC721 standard gives us a nice way to represent our collectibles on the blockchain in form of uinque tokens and with platforms like OpenSea, it's easier than ever to buy, sell, and trade these unique tokens. So irrespective of your background, NFTs are worth exploring.
Subscribe to my newsletter
Read articles from Jeffrey Owoloko directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by