Create an ERC-721 Token with OpenZeppelin

Ryan Harris
InstructorRyan Harris
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

ERC-721 is the Non-Fungible Token (NFT) standard that implements an API for tokens inside of Smart Contracts.

Luckily, the OpenZeppelin library makes it easy to enforce this standard with the ERC721URIStorage class! We just import the ERC721URIStorage class and specify that our contract is an instance of it. Then, set the return type in our constructor to ERC721.

Instructor: [0:00] We have a functioning smart contract on our local blockchain, but we want to make sure we're enforcing the ERC721 standard.

[0:07] Like many NFT projects, we're going to be using the OpenZeppelin library. This allows us to use best practices by importing utilities and base classes. We're going to come into our smart contract and import @openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol. This specific class allows us to set metadata on a per-token basis. You can read more about it in the OpenZeppelin docs.

[0:43] Next, we're going to update our contract to inherit the new base class we've imported. I'm going to copy and paste it, and say, contract YourContract is an instance of ERC721URIStorage. Then, I'm going to come down to the constructor and update its return type to an ERC721 token, with the name, NFTix, and the symbol, NFTX.

[1:10] Before we redeploy to our local blockchain, let's update the name of our contract and call it NFTixBooth. Then, we're also going to rename the file, and call it nftix-booth to match the contract name. We'll also need to update our deploy script. Instead of referring to YourContract, we need to change this to the new contract name, NFTixBooth, and then change all the instances of that in this file.

[1:44] Then, we also need to go into our React application, go into sources and go into App.jsx. Here, we need to change the name, YourContract, to NFTixBooth as well. Now we can redeploy the script. You can see in the UI, we have a new smart contract name. We have some new methods from the ERC721 standard, we have a new ERC721 name, NFTix, and we also have a new symbol, NFTX.

[2:22] In review, we use the ERC721 URI storage class from the OpenZeppelin library to enforce the standards of an ERC721 token. We also change the name of our smart contract, and gave the NFTs it generates a name and a symbol.

egghead
egghead
~ 49 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today