0Pricing
Web3 & DApp Development Fundamentals · درس

معايير ERC ‏(ERC-20 وERC-721)

ادرسوا معايير Ethereum Request for Comments (ERC) الشائعة، مثل ERC-20 للرموز القابلة للاستبدال وERC-721 للرموز غير القابلة للاستبدال (NFTs).

معايير ERC ‏(ERC-20 وERC-721) درس مجاني في Web3 & DApp Development Fundamentals على CoddyKit. هذا هو الدرس 1 من أصل 3. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web3 & DApp Development Fundamentals، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web3 & DApp Development Fundamentals 3 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What are ERC Standards?

ERC stands for Ethereum Request for Comments. These are official proposals that define specific rules and functionalities for smart contracts on the Ethereum blockchain.

Think of them as blueprints or common agreements. They ensure that different contracts and applications can 'speak the same language' and interact seamlessly.

Understanding ERC-20 Tokens

An ERC-20 token is a standard for fungible tokens. Fungible means each unit is identical and interchangeable with another, just like regular currency.

If you have one dollar, it's the same as any other dollar. ERC-20 tokens are used for cryptocurrencies, stablecoins, and utility tokens.

ERC-20: Basic Operations

The ERC-20 standard defines a set of functions and events that all compliant tokens must implement. Key functions include:

  • totalSupply(): Returns the total number of tokens.
  • balanceOf(address account): Gets the balance of an address.
  • transfer(address recipient, uint256 amount): Sends tokens from the caller to a recipient.

ERC-20: Simple Transfer

Here's a simplified contract demonstrating the core idea of an ERC-20 token's transfer function. It manages balances and allows sending tokens.

Try deploying this in Remix and transferring tokens!

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    contract SimpleToken {
        string public name = "MySimpleToken";
        string public symbol = "MST";
        uint8 public decimals = 18;
        uint256 public totalSupply = 1000000 * (10 ** decimals);

        mapping(address => uint256) public balances;

        constructor() {
            balances[msg.sender] = totalSupply;
        }

        function transfer(address recipient, uint256 amount)
            public returns (bool)
        {
            require(balances[msg.sender] >= amount, "Insufficient balance");
            balances[msg.sender] -= amount;
            balances[recipient] += amount;
            return true;
        }

        function balanceOf(address account)
            public view returns (uint256)
        {
            return balances[account];
        }
    }

ERC-20: Approve & TransferFrom

To allow other contracts (like decentralized exchanges) to spend tokens on your behalf, ERC-20 uses allowances:

  • approve(address spender, uint256 amount): Allows a spender to withdraw up to amount from your account.
  • transferFrom(address sender, address recipient, uint256 amount): Transfers tokens from sender to recipient, usually called by a spender who has an allowance.

Introducing ERC-721 NFTs

ERC-721 tokens are for non-fungible tokens (NFTs). Non-fungible means each token is unique and cannot be replaced by another.

Think of a unique piece of art or a specific collectible card. NFTs are used for digital art, unique game items, land in virtual worlds, and more.

ERC-721: Ownership & Transfers

The ERC-721 standard also defines specific functions:

  • ownerOf(uint256 tokenId): Returns the owner of a specific token ID.
  • balanceOf(address owner): Returns the number of NFTs an owner has.
  • safeTransferFrom(address from, address to, uint256 tokenId): Safely transfers a specific NFT from one address to another.

ERC-721: Simple NFT Minting

This contract shows a basic way to 'mint' (create) unique NFTs and track their ownership. Each NFT has a unique tokenId.

After deploying, try calling the mint function multiple times!

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    contract SimpleNFT {
        string public name = "MySimpleNFT";
        string public symbol = "SNFT";
        uint256 private _nextTokenId;

        mapping(uint256 => address) public ownerOf;
        mapping(address => uint256) public balanceOf;

        constructor() {
            _nextTokenId = 0;
        }

        function mint(address recipient)
            public returns (uint256)
        {
            _nextTokenId++;
            uint256 newTokenId = _nextTokenId;
            ownerOf[newTokenId] = recipient;
            balanceOf[recipient]++;
            return newTokenId;
        }
    }

ERC-20 vs. ERC-721: Key Differences

Here's a quick comparison:

  • Fungibility: ERC-20 tokens are fungible (interchangeable); ERC-721 tokens are non-fungible (unique).
  • Uniqueness: ERC-20 tokens are tracked by quantity; ERC-721 tokens are tracked by unique IDs.
  • Use Cases: ERC-20 for currencies, voting rights; ERC-721 for digital art, collectibles, deeds.

Identify the Standards

Which of the following statements correctly describe the characteristics or use cases of ERC-20 and ERC-721 tokens?

Recap: ERC Standards

We've explored two foundational Ethereum standards:

  • ERC-20 for fungible tokens, ideal for currencies and utility tokens.
  • ERC-721 for non-fungible tokens (NFTs), perfect for unique digital assets like art and collectibles.

These standards are crucial for interoperability and building a wide range of DApps on Ethereum.

الأسئلة الشائعة

هل درس «معايير ERC ‏(ERC-20 وERC-721)» مجاني؟

نعم — نص درس «معايير ERC ‏(ERC-20 وERC-721)» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web3 & DApp Development Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Web3 & DApp Development Fundamentals 3 دروس في المجموع.

ماذا ستتعلم في «معايير ERC ‏(ERC-20 وERC-721)»؟

ادرسوا معايير Ethereum Request for Comments (ERC) الشائعة، مثل ERC-20 للرموز القابلة للاستبدال وERC-721 للرموز غير القابلة للاستبدال (NFTs). تتمرن على Web3 & DApp Development Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Web3 & DApp Development Fundamentals؟

لا تُشترط خبرة سابقة. Web3 & DApp Development Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 3.

كم من الوقت يستغرق درس «معايير ERC ‏(ERC-20 وERC-721)»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Web3 & DApp Development Fundamentals هذا؟

نعم. كل درس في Web3 & DApp Development Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. معايير ERC ‏(ERC-20 وERC-721)
  2. أفضل ممارسات أمان العقود
  3. العقود القابلة للترقية
← العودة إلى Web3 & DApp Development Fundamentals