0Pricing
Web3 & DApp Development Fundamentals · Leçon

Frappe et destruction

Gestion de l’offre

Frappe et destruction est une leçon Web3 & DApp Development Fundamentals gratuite sur CoddyKit. Ceci est la leçon 4 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.

Managing Supply

Minting creates new tokens and burning destroys them. Together they let a token's totalSupply grow or shrink over time.

These operations are not part of the core ERC-20 interface, but they are extremely common extensions.

What Minting Does

Minting increases totalSupply and credits new tokens to a recipient's balance. It is how tokens enter circulation - at deployment, as rewards, or on demand.

Implementing Mint

A mint function adds to both totalSupply and the recipient's balance, then emits a Transfer event from the zero address.

<code>function _mint(address to, uint256 amount) internal {
    require(to != address(0), 'mint to zero');
    totalSupply += amount;
    balanceOf[to] += amount;
    emit Transfer(address(0), to, amount);
}</code>

Mint Emits From Zero

By convention a mint is logged as a Transfer from address(0). Wallets and indexers interpret a transfer originating at the zero address as new tokens being created.

<code>emit Transfer(address(0), to, amount); // signals minting</code>

What Burning Does

Burning reduces totalSupply and subtracts from a holder's balance, permanently removing tokens from circulation. It is used for deflationary mechanics, redemptions, and buybacks.

Implementing Burn

A burn function checks the holder's balance, decreases it and totalSupply, then emits a Transfer to the zero address.

<code>function _burn(address from, uint256 amount) internal {
    require(balanceOf[from] >= amount, 'burn exceeds balance');
    balanceOf[from] -= amount;
    totalSupply -= amount;
    emit Transfer(from, address(0), amount);
}</code>

Burn Emits To Zero

Symmetrically, a burn is logged as a Transfer to address(0). Tokens sent to the zero address are unrecoverable, which is exactly the intent.

<code>emit Transfer(from, address(0), amount); // signals burning</code>

Access Control on Mint

Minting must be restricted - an open mint function lets anyone create unlimited tokens, destroying value. Gate it behind an owner or minter role.

<code>address public owner;
modifier onlyOwner() { require(msg.sender == owner, 'not owner'); _; }

function mint(address to, uint256 amount) public onlyOwner {
    _mint(to, amount);
}</code>

Burning Your Own Tokens

Holders are usually allowed to burn their own tokens freely. A public burn simply burns from msg.sender.

<code>function burn(uint256 amount) public {
    _burn(msg.sender, amount);
}</code>

Capped Supply

To guarantee scarcity, a token can enforce a maximum supply by checking against a cap before minting.

<code>uint256 public immutable cap;

function mint(address to, uint256 amount) public onlyOwner {
    require(totalSupply + amount <= cap, 'cap exceeded');
    _mint(to, amount);
}</code>

Burn From Allowance

Like transferFrom, a burnFrom lets an approved spender burn another account's tokens, decrementing the allowance first.

<code>function burnFrom(address from, uint256 amount) public {
    require(allowance[from][msg.sender] >= amount, 'allowance');
    allowance[from][msg.sender] -= amount;
    _burn(from, amount);
}</code>

Quick Check

Test your understanding of minting and burning.

Recap

You learned supply management:

  • Mint increases totalSupply, credits a balance, emits Transfer from address(0)
  • Burn decreases totalSupply, debits a balance, emits Transfer to address(0)
  • Minting must be access-controlled; holders can usually burn their own tokens
  • Caps enforce a maximum supply; burnFrom uses allowances

Questions Fréquemment Posées

La leçon « Frappe et destruction » est-elle gratuite ?

Oui — le texte complet de « Frappe et destruction » 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 « Frappe et destruction » ?

Gestion de l’offre 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 4 sur 4.

Combien de temps prend la leçon « Frappe et destruction » ?

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.

Toutes les leçons de ce cours

  1. Norme ERC-20
  2. Implémenter un jeton
  3. Autorisations
  4. Frappe et destruction
← Retour à Web3 & DApp Development Fundamentals