Are you a Web3 developer? Help us improve the Chiliz Chain docs! Share your opinion
in less than 2 minutes
Chiliz Chain Developer Docs
Chiliz ChainBlock ExplorerCommunitySocios.com
Tiếng Việt / Vietnamese
Tiếng Việt / Vietnamese
  • Tài liệu Chiliz Chain
  • Bắt Đầu Nhanh
    • Chiliz Chain Trong Tóm Lược
    • Kết nối với Mainnet và Testnet
    • Nhận Token Trên Testnet
    • Triển khai và xác minh một hợp đồng
      • Triển khai với Remix IDE
        • ERC-20 smart contract
      • Triển khai với thirdweb
      • Xác minh với Chiliscan
      • Xác minh với Chiliz Block Explorer
    • Chạy một Node Chiliz Chain
    • Khóa học trực tuyến miễn ph
    • Địa chỉ Phân bổ Nguồn cung Lạm phát
  • Học tập
    • Về Chiliz Chain
      • 2024 Dragon8 hard fork
      • Tokenomics
      • Chiliz Labs
    • Chiliz Bridge
      • Cách bridge CHZ của bạn
    • Staking trên Chiliz Chain
      • Stake CHZ của bạn
      • Unstake CHZ của bạn
      • Phần Thưởng Staking
      • Staking CHZ từ ví Ledger của bạn
    • Trở thành Nhà Xác Thực
      • Chạy một node Nhà xác thực
      • Hình phạt cho nhà xác thực
  • Phát triển
    • Cơ bản
      • Sử dụng MetaMask
        • Cài đặt MetaMask
        • Liên kết Chiliz Chain với MetaMask
      • Kết nối với Chiliz Chain
        • Kết nối bằng RPC
        • Chạy một Node Chiliz Chain
        • Sử dụng ví phần cứng
      • Block Explorers
      • Spicy Faucets
      • Nhận Wrapped CHZ
      • Mẹo & Thủ thuật
    • Nâng cao
      • Cách sử dụng Account Abstraction
      • Cách sử dụng Oracle
      • Cách sử dụng RNG
Powered by GitBook
On this page
  • Tạo token của riêng bạn
  • ERC-20 smart contract

Was this helpful?

  1. Bắt Đầu Nhanh
  2. Triển khai và xác minh một hợp đồng
  3. Triển khai với Remix IDE

ERC-20 smart contract

Tạo token của riêng bạn

Theo phương pháp hay nhất, bạn có thể chọn tạo token của riêng mình sử dụng mẫu chuẩn ERC-20.

Sử dụng hợp đồng thông minh sau trong trình soạn thảo mã của bạn, tùy chỉnh đồng tiền điện tử của bạn, và biên dịch mã của bạn sau khi chấp thuận kết nối sử dụng ví điện tử ưa thích của bạn (ở đây, Ví MetaMask được sử dụng).

ERC-20 smart contract

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.16;

interface IERC20 {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

contract SampleERC20Token is IERC20 {
    string public symbol;
    string public  name;
    uint8 public decimals;
    uint public _totalSupply;
    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;

    constructor() {
        symbol = "SYM";
        name = "Sample ERC20 Token";
        decimals = 2;
        _totalSupply = 100000;
        balances[msg.sender] = _totalSupply;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }
    function totalSupply() external view returns (uint) {
        return _totalSupply  - balances[address(0)];
    }
    function balanceOf(address tokenOwner) external view returns (uint balance) {
        return balances[tokenOwner];
    }
    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = balances[msg.sender] - tokens;
        balances[to] = balances[to] + tokens;
        emit Transfer(msg.sender, to, tokens);
        return true;
    }
    function approve(address spender, uint tokens) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }
    function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        balances[from] = balances[from] - tokens;
        allowed[from][msg.sender] = allowed[from][msg.sender] - tokens;
        balances[to] = balances[to] + tokens;
        emit Transfer(from, to, tokens);
        return true;
    }
    function allowance(address tokenOwner, address spender) external view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }
}

Last updated 1 year ago

Was this helpful?