ERC721 - OpenZeppelin Docs (2024)

We’ve discussed how you can make a fungible token using ERC20, but what if not all tokens are alike? This comes up in situations like real estate or collectibles, where some items are valued more than others, due to their usefulness, rarity, etc. ERC721 is a standard for representing ownership of non-fungible tokens, that is, where each token is unique.

ERC721 is a more complex standard than ERC20, with multiple optional extensions, and is split accross a number of contracts. The OpenZeppelin Contracts provide flexibility regarding how these are combined, along with custom useful extensions. Check out the API Reference to learn more about these.

Constructing an ERC721 Token Contract

We’ll use ERC721 to track items in our game, which will each have their own unique attributes. Whenever one is to be awarded to a player, it will be minted and sent to them. Players are free to keep their token or trade it with other people as they see fit, as they would any other asset on the blockchain!

Here’s what a contract for tokenized items might look like:

pragma solidity ^0.5.0;import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";import "@openzeppelin/contracts/drafts/Counters.sol";contract GameItem is ERC721Full { using Counters for Counters.Counter; Counters.Counter private _tokenIds; constructor() ERC721Full("GameItem", "ITM") public { } function awardItem(address player, string memory tokenURI) public returns (uint256) { _tokenIds.increment(); uint256 newItemId = _tokenIds.current(); _mint(player, newItemId); _setTokenURI(newItemId, tokenURI); return newItemId; }}

The ERC721Full contract includes all standard extensions, and is probably the one you want to use. In particular, it includes ERC721Metadata, which provides the _setTokenURI method we use to store an item’s metadata.

Also note that, unlike ERC20, ERC721 lacks a decimals field, since each token is distinct and cannot be partitioned.

New items can be created:

> gameItem.awardItem(playerAddress, "https://game.example/item-id-8u5h2m.json")7

And the owner and metadata of each item queried:

> gameItem.ownerOf(7)playerAddress> gameItem.tokenURI(7)"https://game.example/item-id-8u5h2m.json"

This tokenURI should resolve to a JSON document that might look something like:

{ "name": "Thor's hammer", "description": "Mjölnir, the legendary hammer of the Norse god of thunder.", "image": "https://game.example/item-id-8u5h2m.png", "strength": 20}

For more information about the tokenURI metadata JSON Schema, check out the ERC721 specification.

you’ll notice that the item’s information is included in the metadata, but that information isn’t on-chain! So a game developer could change the underlying metadata, changing the rules of the game! If you’d like to put all item information on-chain, you can extend ERC721 to do so (though it will be rather costly). You could also leverage IPFS to store the tokenURI information, but these techniques are out of the scope of this overview guide.
ERC721 - OpenZeppelin Docs (2024)

FAQs

What is the standard for OpenZeppelin NFT? ›

ERC721 is a standard for representing ownership of non-fungible tokens, that is, where each token is unique. ERC721 is a more complex standard than ERC20, with multiple optional extensions, and is split accross a number of contracts.

What is totalSupply in ERC721? ›

The ERC721A contract comes with a totalSupply function that returns the total number of NFTs that have been minted in the collection (including tokens that have been burned). This means you can already view the total supply of NFTs in the collection by implementing the ERC721A contract.

How to create ERC721 token OpenZeppelin? ›

How to create an ERC721 token with OpenZeppelin
  1. Let's get started. Go to the OpenZeppelin Contracts Wizard and click on ERC721. ...
  2. Let's add some features. ...
  3. Let's set the access control. ...
  4. Let's add upgradeability. ...
  5. Let's add a security contact. ...
  6. Download your smart contract code. ...
  7. Compile the smart contract. ...
  8. Deploy the smart contract.
Mar 24, 2023

What is ERC-721 used for? ›

ERC-721 is an open standard that describes how to build Non-Fungible tokens on EVM (Ethereum Virtual Machine) compatible blockchains; it is a standard interface for Non-Fungible tokens; it has a set of rules which make it easy to work with NFTs. NFTs are not only of ERC-721 type; they can also be ERC-1155 tokens.

What is the most popular NFT standard? ›

ERC token is the most widely used standard for NFTs. ERC means "Ethereum Request for Comment," and represents a subcategory of Ethereum Improvement Proposals (EIPs). The Ethereum community proposes changes, improvements, or additions to the Ethereum network through these EIPs.

What is the difference between ERC-721 and ERC 1155? ›

This means that ERC-1155 tokens can be used for fractional ownership or as a form of currency, while ERC-721 tokens are typically used for digital collectibles and other unique digital assets. Another difference is that ERC-721 tokens can only be traded one at a time, while ERC-1155 tokens can be traded in bulk.

What is the alternative to ERC-721? ›

ERC-1155 improves upon the functionality of ERC-721, increasing its efficiency and correcting evident implementation errors. It can support an infinite quantity of tokens in a single contract, underpinning fungible, semi-fungible, and NFTs, which can transition between both of the former during its lifecycle.

What is the difference between ERC20 and ERC-721 tokens? ›

The key difference between ERC20 and ERC721 tokens lies in their fungibility. ERC20 tokens are fungible and represent a uniform asset, while ERC721 tokens are non-fungible and symbolize a set of unique assets. Additionally, ERC721 tokens cannot be divided into smaller units.

Is ERC-721 divisible? ›

However, the same is not possible with ERC20 due to their fungible characteristics. ERC20 tokens can be divided in any number of ways. Even sharing 0.1 % of your token is possible. On the other hand, ERC721 tokens are not-divisible.

How much does it cost to create an ERC token? ›

On average, the cost to create ERC20 token lies between $5000 to $10,000, depending on the type of token developed and business requirements.

Is ERC721 transferable? ›

Hook for transferring ERC721 or ERC1155 NFTs to another wallet address. Available to use on contracts that implement either the ERC721 and ERC1155 interfaces, such as the Edition or NFT Collection .

Can I create my own NFT token? ›

An NFT carries a unique digital certificate to prove ownership. You can make your own NFT out of any digital format, such as audio, video, or GIF. Most people creating NFT art start with digital 2D artwork. Learning how to make NFTs is not only fun but could be lucrative if your NFT catches the eye of collectors.

Is ERC-721 free? ›

ERC-721 is a free, open standard that describes how to build non-fungible or unique tokens on the Ethereum blockchain. While most tokens are fungible (every token is the same as every other token), ERC-721 tokens are all unique.

Does each ERC-721 token have its own address? ›

Each token has a unique identifier and the contract stores which address owns each identifier. Operator Approvals: In addition to per-token approvals, ERC721 also introduces the concept of operator approvals. This allows a token owner to approve another address (an "operator") to manage all their tokens.

Does Ledger support ERC-721? ›

You can receive Ethereum NFTs (ERC721) in Ledger Live. To do that, you can simply send the NFT to your receiving Ethereum address. Learn how to receive assets here.

What are the standard dimensions for NFT? ›

This can range from anywhere around 300px x 300px, up to lengths and widths of 4000px or more. The best NFT art is usually minted with a horizontal resolution of 4000px, as this ensures 4K HD resolution, making it easier to share at full quality across platforms. Around 1920 x 1080px is classed as 'regular' HD quality.

What is NFT standards? ›

NFC standards cover communications protocols and data exchange formats and are based on existing radio-frequency identification (RFID) standards including ISO/IEC 14443 and FeliCa. The standards include ISO/IEC 18092 and those defined by the NFC Forum.

What is the recommended NFT size for OpenSea? ›

What is the recommended NFT size for OpenSea? OpenSea recommends a minimum of 512×512 pixels for NFT images, but 1000×1000 to 2000×2000 pixels provides better image quality.

What is the flow fungible token standard? ›

The Fungible Token Standard defines what a fungible token should look like on Flow. Wallets and other platforms need to recognize these tokens, so they adhere to a specific interface, which defines fields like balance, totalSupply, withdraw functionality, and more.

Top Articles
3 Tips to Go From First-Time Entrepreneur to Seasoned Business Owner | ZenBusiness Inc.
ELFI | How Much Can You Take Out In Student Loans?
Unit 30 Quiz: Idioms And Pronunciation
Chicago Neighborhoods: Lincoln Square & Ravenswood - Chicago Moms
Dollywood's Smoky Mountain Christmas - Pigeon Forge, TN
Dew Acuity
Top Scorers Transfermarkt
Phone Number For Walmart Automotive Department
Call Follower Osrs
27 Places With The Absolute Best Pizza In NYC
Noaa Weather Philadelphia
Produzione mondiale di vino
Music Archives | Hotel Grand Bach - Hotel GrandBach
Monticello Culver's Flavor Of The Day
Bill Devane Obituary
Lantana Blocc Compton Crips
Thayer Rasmussen Cause Of Death
Brutál jó vegán torta! – Kókusz-málna-csoki trió
Premier Reward Token Rs3
Lesson 8 Skills Practice Solve Two-Step Inequalities Answer Key
Echat Fr Review Pc Retailer In Qatar Prestige Pc Providers – Alpha Marine Group
Everything We Know About Gladiator 2
Vipleaguenba
Lcwc 911 Live Incident List Live Status
Nordstrom Rack Glendale Photos
Walgreens Tanque Verde And Catalina Hwy
Gopher Hockey Forum
Ubg98.Github.io Unblocked
Is A Daytona Faster Than A Scat Pack
Diakimeko Leaks
Bjerrum difference plots - Big Chemical Encyclopedia
Play It Again Sports Norman Photos
Costco Gas Hours St Cloud Mn
Ihub Fnma Message Board
Sadie Sink Reveals She Struggles With Imposter Syndrome
Craigslist Comes Clean: No More 'Adult Services,' Ever
Amazing Lash Bay Colony
Rogold Extension
Missing 2023 Showtimes Near Mjr Southgate
Vlocity Clm
The Ultimate Guide to Obtaining Bark in Conan Exiles: Tips and Tricks for the Best Results
Roch Hodech Nissan 2023
Kokomo Mugshots Busted
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Rogers Centre is getting a $300M reno. Here's what the Blue Jays ballpark will look like | CBC News
Scarlet Maiden F95Zone
Craigslist Woodward
Kaamel Hasaun Wikipedia
Walmart Listings Near Me
Mytmoclaim Tracking
WHAT WE CAN DO | Arizona Tile
One Facing Life Maybe Crossword
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 5822

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.