ERC-721 Non-Fungible Token Standard

Introduction

What Are Non-Fungible Tokens (NFTs)?

Non-Fungible Tokens (NFTs) uniquely identify individuals or objects on the blockchain. These tokens are ideal for platforms selling items like collectibles, digital keys, event tickets, or exclusive merchandise. Their potential is vast, necessitating a robust standard—enter ERC-721.

What Is ERC-721?

ERC-721 is the Ethereum standard for NFTs, ensuring each token is distinct. Unlike fungible tokens (e.g., ERC-20), an ERC-721 token’s value may differ based on attributes like rarity, age, or visual traits. Each NFT has a unique tokenId (a uint256 variable), making the pair (contract address, tokenId) globally unique. This enables decentralized apps to use tokenId to generate dynamic outputs, such as digital art, game assets, or even virtual pets like CryptoKitties!

Prerequisites

  • Ethereum Accounts: Understand wallet addresses and key management.
  • Smart Contracts: Basics of deploying and interacting with contracts.
  • Token Standards: Familiarity with ERC-20 or other token protocols.

Core Concepts of ERC-721

Proposed in January 2018 by William Entriken, Dieter Shirley, Jacob Evans, and Nastassia Sachs, ERC-721 defines an API for NFTs within smart contracts. Key features include:

  1. Token Transfers: Move tokens between accounts.
  2. Balance Queries: Check an account’s NFT holdings.
  3. Ownership Tracking: Identify the owner of a specific tokenId.
  4. Supply Metrics: Monitor total tokens minted.
  5. Approval Mechanisms: Authorize third parties to manage tokens.

Methods and Events

A contract becomes ERC-721 compliant by implementing these methods and events:

Methods

solidity
function balanceOf(address _owner) external view returns (uint256);
function ownerOf(uint256 _tokenId) external view returns (address);
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
// ... (simplified for brevity)

Events

solidity
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);

👉 Explore real-world NFT projects


Practical Example: Interacting with ERC-721

Web3.py Script

Below is a Python script to query NFT data using Web3.py:

“`python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider(“https://cloudflare-eth.com”))
contract_address = “0x06012c8cf97BEaD5deAe237070F9587f8E7A266d” # CryptoKitties
abi = […] # Simplified ABI for balanceOf, ownerOf, etc.

nft_contract = w3.eth.contract(address=contract_address, abi=abi)
print(f”Contract Name: {nft_contract.functions.name().call()}”)
“`

Output:

CryptoKitties [CK] NFTs in Auctions: 5


Popular NFT Projects

Project Description
CryptoKitties Breedable, collectible virtual cats with unique traits.
ENS Domains Decentralized naming for wallets and websites (e.g., vitalik.eth).
Bored Ape YC 10,000 unique art pieces doubling as exclusive community membership tokens.

👉 Discover top NFT marketplaces


FAQs

1. How does ERC-721 differ from ERC-20?

  • ERC-20: Fungible tokens (e.g., stablecoins) where each unit is identical.
  • ERC-721: Each token is unique (e.g., digital art, collectibles).

2. Can ERC-721 tokens be fractionalized?

No, but protocols like ERC-1155 allow semi-fungibility.

3. What’s the gas cost for minting an NFT?

Varies by network congestion; expect 50,000–200,000 gas.


Further Reading