Norme ERC-721
Jetons non fongibles
Norme ERC-721 est une leçon Web3 & DApp Development Fundamentals gratuite sur CoddyKit. Ceci est la leçon 1 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Web3 & DApp Development Fundamentals, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Web3 & DApp Development Fundamentals comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
What Is ERC-721?
ERC-721 is the standard for non-fungible tokens (NFTs). Unlike ERC-20, each token is unique and identified by a distinct tokenId.
NFTs represent ownership of one-of-a-kind items: art, collectibles, in-game assets, and more.
Fungible vs Non-Fungible
The key contrast:
- ERC-20 - all tokens identical and interchangeable, tracked by balance
- ERC-721 - each token unique, tracked by owner per tokenId
You own specific token #42, not a fraction of a pool.
Core Ownership Functions
ERC-721 tracks ownership with two key views:
ownerOf(tokenId)- who owns a specific tokenbalanceOf(owner)- how many tokens an address owns
<code>function ownerOf(uint256 tokenId) external view returns (address);
function balanceOf(address owner) external view returns (uint256);</code>Transfer Functions
ERC-721 provides transferFrom and the safer safeTransferFrom, which checks that a receiving contract can handle NFTs.
<code>function transferFrom(address from, address to, uint256 tokenId) external;
function safeTransferFrom(address from, address to, uint256 tokenId) external;</code>Approval Functions
Owners can authorize others to transfer specific tokens with approve, or grant blanket permission over all their tokens with setApprovalForAll.
<code>function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool approved) external;
function getApproved(uint256 tokenId) external view returns (address);
function isApprovedForAll(address owner, address operator) external view returns (bool);</code>Required Events
ERC-721 defines three events: Transfer, Approval, and ApprovalForAll. Note the tokenId is indexed so transfers of a specific NFT are easy to track.
<code>event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);</code>safeTransferFrom and onERC721Received
safeTransferFrom protects against NFTs getting stuck. If the recipient is a contract, it must implement onERC721Received and return the correct magic value, otherwise the transfer reverts.
<code>// receiving contract must implement:
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
external returns (bytes4);</code>The Metadata Extension
Most NFTs implement the optional metadata extension adding name(), symbol(), and crucially tokenURI(tokenId), which points to the token's off-chain JSON metadata.
<code>function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);</code>ERC-165 Interface Detection
ERC-721 builds on ERC-165, which lets contracts advertise which interfaces they support via supportsInterface. Marketplaces use it to detect NFTs.
<code>function supportsInterface(bytes4 interfaceId) external view returns (bool);</code>Using OpenZeppelin ERC721
As with ERC-20, the practical approach is to inherit OpenZeppelin's audited ERC721 implementation and add your minting logic.
<code>// import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
// contract MyNFT is ERC721 {
// constructor() ERC721('MyNFT', 'MNFT') {}
// }</code>Where the Asset Lives
An NFT on-chain is just an id and an owner. The actual image or media usually lives off-chain (often on IPFS), referenced by the tokenURI. The chain proves ownership, not the file itself.
Quick Check
Test your understanding of the ERC-721 standard.
Recap
You learned the ERC-721 standard:
- NFTs are unique, identified by tokenId, tracked via
ownerOf - Transfers use
transferFromand safersafeTransferFrom - Approvals: per-token
approveand blanketsetApprovalForAll - Metadata extension adds
tokenURI; ERC-165 enables interface detection - Assets usually live off-chain, referenced by the URI
Questions Fréquemment Posées
La leçon « Norme ERC-721 » est-elle gratuite ?
Oui — le texte complet de « Norme ERC-721 » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Web3 & DApp Development Fundamentals, passe à CoddyKit PRO. Le cours Web3 & DApp Development Fundamentals comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Norme ERC-721 » ?
Jetons non fongibles Tu pratiques Web3 & DApp Development Fundamentals avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Web3 & DApp Development Fundamentals ?
Aucune expérience préalable n'est requise. Web3 & DApp Development Fundamentals sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 1 sur 4.
Combien de temps prend la leçon « Norme ERC-721 » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Web3 & DApp Development Fundamentals ?
Oui. Chaque leçon Web3 & DApp Development Fundamentals inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.