What is an ERC721 contract: I created my own ERC721 contract!

What is an ERC721 contract: I created my own ERC721 contract!

Walkthrough of ERC 721

What is ERC-721?

Imagine unique digital items like artwork, collectibles, or even game characters. ERC721 is like a special recipe that tells blockchains how to keep track of these one-of-a-kind items.

Think of Ethereum as a giant computer with special programs called "smart contracts". These contracts can follow rules for things like money or digital items. ERC721 is a set of instructions (like a recipe) that tells these smart contracts how to handle unique things, not just regular money.

Here's the cool part: Anyone can use this recipe to create their own unique digital items on blockchains like Ethereum. This makes it possible to buy, sell, and trade these items securely, knowing they're truly one-of-a-kind.

Key points to remember:

  • ERC721 stands for "Ethereum Request for Comment 721" - Not the most memorable name, but it does the job!

  • It's a set of rules for tracking unique digital items on blockchains. - Like a special label for special things.

  • Anyone can use it to create and trade these items securely. - Opens up a world of possibilities!

Functions in ERC-721:

We have functions ranging from approve, getApproved, safeTransferFrom, isApprovedForAll, setApprovalForAll, approve, transferFrom, transferFrom, ownerOf, balanceOf.

Imagine you have a collection of unique trading cards, each with its own number. ERC721 functions are like special tools for keeping track of those cards on the blockchain.

  • balanceOf: This tool tells you how many unique cards you own (not regular playing cards, remember!).

  • ownerOf: This tool tells you who owns a specific card by its unique number.

  • safeTransferFrom: This tool lets you securely give a card to someone else on the blockchain, like trading with a friend. It even checks if the receiver is ready to accept it!

  • transferFrom: Similar to "safeTransferFrom," but only use it if the receiver already gave you permission to move their card.

  • approve: This tool lets you give someone temporary permission to move one of your cards, like trusting a friend to hold it for you.

  • getApproved: This tool checks who has permission to move one of your cards, in case you forgot.

  • setApprovalForAll: This is like giving a friend a master key to manage all your cards (not recommended unless you really trust them!).

  • isApprovedForAll: This tool checks if someone has that master key to your cards.

  • safeTransferFrom (with data): Like the regular "safeTransferFrom," but it can also send extra information along with the card, like a little note for the receiver.

Remember, these are just some of the tools in the ERC721 toolbox. There's more to explore, but hopefully, this helps to understand ERC721.

There are several use cases of ERC721, it does ranges from gaming, education, music, identification etc.

I wrote a smart contract that has the implementation of Openzeppelin that allows you to mint NFT.

Here is a walkthrough on the ERC721 Contract i wrote.

I started by stating the license type and stating the solidity version i intend to use for my ERC721 contract.

Next on the smart contract code was import the required libraries for the contract.

ERC721.sol is the contract for implementation of the ERC721 standard is imported from the OpenZeppelin library, ERC721URIStorage.sol is used for Metadata URIs, for storing and managing metadata URIs associated with NFTs. ERC721Burnable.sol is used to burn and destroy nfts, like burning a card, Ownable.sol is used for User Access Control.

In the contract constructor takes in address of owner, NFT Token name and Symbol, and its calling the ownable contract.

I declared a function safeMint that takes in three arguments: to (the address of the receiver of the NFT token), tokenId (the unique identifier for the token), and uri (the URI of the JSON file associated with the token). The function can only be called by the contract deployer which we used the Ownable contract to implement

whenever the ERC721 contract deployer wants to mint a new token by calling the _safeMint function inherited from the ERC721 contract. It creates a new token and assigns it to the specified receiver's address.

There's another special function (_setTokenURI) to attach information (like the card's image or description) to a specific card (identified by its unique number). Think of it like writing a note on the back of your card!. This ensures anyone can see the card's details if they know its number. It's like letting everyone admire the artwork on your card!

The supportsInterface function makes sure your code follows the rules of creating NFTs according to ERC721*&*ERC721URIStorage contracts that we imported at the beginning of the code. It's like following specific game rules in a game.