Chuyển mã thông báo bằng web3 python 2024

Xem Chuyển mã thông báo bằng web3 python 2024

Mã thông báo ERC20 là đại diện của một thứ gì đó trên Chuỗi khối Ethereum. Mã thông báo ERC20 đã trở nên rất hữu ích và đã tìm thấy các ứng dụng trong nhiều lĩnh vực

mục tiêu

Trong bài viết này, chúng tôi sẽ xem xét những gì bạn cần để triển khai và giao dịch mã thông báo ERC20 của riêng bạn, bằng cách thực hiện như sau

  • Tạo mã thông báo ERC20 của riêng bạn
  • Triển khai mã thông báo của bạn vào một chuỗi khối cục bộ
  • Thực hiện giao dịch bằng mã thông báo của bạn
  • Tạo một hợp đồng thông minh tương tác với mã thông báo của bạn

điều kiện tiên quyết

  • Đã cài đặt Visual Studio Code (VS Code)
  • Đã cài đặt môi trường Brownie Python
  • Một số kiến ​​thức cơ bản về ngôn ngữ lập trình Python
  • Một số kiến ​​thức trước về ngôn ngữ lập trình Solidity

Mục lục

  1. Khởi tạo
  2. Triển khai mã thông báo
  3. Giao dịch bằng token
  4. Tạo Hợp đồng thông minh giao dịch Mã thông báo

    Khởi tạo

    Tạo một thư mục mới ERC20. Mở nó trong Mã VS. mở thiết bị đầu cuối

    brownie init
    

    Triển khai mã thông báo

    Tạo một tệp trong thư mục

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    1 có tên là

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    2. Nó sẽ chứa tất cả các cấu hình của bạn

    Cách dễ nhất để triển khai hợp đồng ERC20 là sử dụng thư viện của

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    3. Hợp đồng thông minh của họ được kiểm tra kỹ lưỡng và tin cậy bởi các công ty tiền điện tử hàng đầu

    Các phụ thuộc từ

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    3 sẽ được chứa trong tệp

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    2

    dependencies:
      - OpenZeppelin/[email protected]
    
    compiler:
      solc:
        remappings:
          - '@openzeppelin=OpenZeppelin/[email protected]'
    

    Bây giờ vào sự kiện chính. Tạo mã thông báo MyToken của riêng bạn. sol. Lưu tệp trong thư mục hợp đồng

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    Để đảm bảo hợp đồng của bạn đã được thiết lập xong, hãy chạy

    ________số 8

    Mã thông báo của bạn có 2 tham số.

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    6 và

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    7. Người sáng lập sẽ nhận được tất cả các mã thông báo từ nguồn cung cấp ban đầu

    Mã thông báo của bạn kế thừa từ ERC20 của OpenZeppelin. Cần 2 tham số.

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    8 và

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    9, đã được đặt tên là

    brownie compile
    

    0 VÀ

    brownie compile
    

    1

    Khi khởi tạo, hợp đồng này cấp mã thông báo

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    7 cho

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    6, thông qua chức năng

    brownie compile
    

    4

    Theo mặc định, mã thông báo ERC20 này sử dụng 18 số thập phân

    Tạo một tệp Python có tên là transact_token. py trong thư mục script

    //SPDX-License-Identifier: MIT
    
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract MyToken is ERC20{
        //Instead of WILLIAM and BILL you can use your names to make this token your own!
        constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
            _mint(_founder,_initialSupply);
        }
    }
    

    8

    MyToken. triển khai () có 3 tham số

    1. Người sáng lập sẽ có mã thông báo được đúc cho họ
    2. Nguồn cung cấp ban đầu là số lượng mã thông báo được đúc cho người sáng lập
    3. Tài khoản triển khai Hợp đồng thông minh mã thông báo ({“từ”. x})

      Điều quan trọng là tài khoản của người sáng lập phải là tài khoản triển khai hợp đồng thông minh. Điều này là do các chức năng trong hợp đồng ERC20 sẽ cho rằng tiền sẽ đến từ tài khoản đã triển khai Hợp đồng thông minh mã thông báo

      brownie compile
      

      5 đã được đặt thành 21 triệu mã thông báo

      brownie compile
      

      6 đã được sử dụng để chuyển đổi 21 triệu thành 18 chữ số thập phân bắt buộc

      Tài khoản bạn sẽ sử dụng để triển khai mã thông báo này sẽ là

      brownie compile
      

      7. Đây là một địa chỉ trên mạng chuỗi khối cục bộ được triển khai bằng cách sử dụng

      brownie compile
      

      8. Brownie có thiết lập

      brownie compile
      

      8 theo mặc định

      Trong thiết bị đầu cuối, chạy

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      4

      Giao dịch bằng Token

      Bạn đã triển khai mã thông báo của mình trên chuỗi khối. Bây giờ bạn cần kiểm tra số dư. Trong giao dịch_token. py tạo một chức năng mới

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      5

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      80 là một chức năng khác được triển khai bởi

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      3 để kiểm tra số dư của mã thông báo được giữ bởi một địa chỉ

      Kiểm tra số dư mã thông báo được cung cấp cho

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      82, người là

      brownie compile
      

      7

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      0

      Chạy

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      4

      Biết rằng

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      84 của bạn có đủ mã thông báo, bây giờ hãy gửi nó đến các tài khoản khác. Trong giao dịch_token. py tạo một chức năng mới

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      3

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      85 nhận được hợp đồng thông minh

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      86 được triển khai gần đây nhất

      Mã thông báo được chuyển từ tài khoản đã triển khai Hợp đồng thông minh mã thông báo. Sau đó, nó được gửi đến địa chỉ người nhận được chỉ định

      Trong hàm

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      87

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      0

      Trong thiết bị đầu cuối, chạy

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      4

      Tạo hợp đồng thông minh giao dịch mã thông báo

      Trong thư mục hợp đồng, tạo một tệp mới QuizReward. sol

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      2

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      88 chứa số được so sánh với.

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      89 chứa số lượng mã thông báo sẽ được gửi cho bất kỳ ai trả lời đúng

      Hàm

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      40 chuyển đổi số đầu vào thành 18 chữ số thập phân

      Hàm

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      41 có 3 tham số. Câu trả lời nhận được, địa chỉ được thanh toán và mã thông báo để thưởng. Phần thưởng chỉ được chuyển đến địa chỉ nếu câu trả lời đúng

      Trong thiết bị đầu cuối, chạy

      ________số 8

      Triển khai hợp đồng thông minh này trong transact_token. py

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      4

      Có 2 cách mà hợp đồng thông minh này có thể thưởng cho người dùng

      Cách đầu tiên là chuyển mã thông báo từ người sáng lập (

      brownie compile
      

      7) sang hợp đồng thông minh. Loại chuyển đổi này đã được chứng minh

      Cách thứ hai là người sáng lập cung cấp cho hợp đồng thông minh một khoản trợ cấp. Một khoản trợ cấp để tiêu tiền của người sáng lập. Hãy coi đó là việc người sáng lập cấp thẻ ghi nợ của cô ấy, nhưng cô ấy có thể giới hạn số tiền mà hợp đồng thông minh có thể chi tiêu. Đây là những gì chúng ta sẽ làm

      Trong giao dịch_token. py tạo một chức năng

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      5

      Người chi tiêu trong trường hợp này sẽ là hợp đồng thông minh

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      6

      Hợp đồng thông minh phần thưởng bài kiểm tra có quyền truy cập vào 6.000.000 mã thông báo của người sáng lập (

      brownie compile
      

      7). Hợp đồng thông minh không nhất thiết phải sở hữu 6.000.000 mã thông báo. Nó chỉ được phép chi tiêu nó

      Tiếp tục trong

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      87

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      7

      giao dịch cuối cùng_token. py sẽ trông như sau

      dependencies:
        - OpenZeppelin/[email protected]
      
      compiler:
        solc:
          remappings:
            - '@openzeppelin=OpenZeppelin/[email protected]'
      

      8

      Cuối cùng, chạy

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      4

      Bạn sẽ nhận được đầu ra này

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      0

      Rõ ràng, hợp đồng thông minh đã có thể chuyển 1000000 mã thông báo vào tài khoản theo yêu cầu. Cũng có thể thấy rằng hợp đồng thông minh không có mã thông báo mà nó sở hữu. Chỉ được phép sử dụng mã thông báo trong tài khoản của người sáng lập

      Đọc thêm

      Để xem tất cả các chức năng ERC20 được kế thừa từ thư viện OpenZeppelin, hãy theo liên kết này. OpenZeppelin ERC20

      Có một vài chức năng chưa được đề cập ở đây

      Ví dụ.

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      45. Điều này trái ngược với

      brownie compile
      

      4. Nó phá hủy các mã thông báo trong tài khoản và giảm tổng nguồn cung đang lưu thông

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      47. Điều này trái ngược với

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      48. Nó làm giảm các mã thông báo mà một địa chỉ được phép chi tiêu trên một tài khoản

      Với những kiến ​​thức cơ bản đã có, bạn có thể dễ dàng điều chỉnh các chức năng này vào mã của mình mà không gặp nhiều rắc rối

      Phần kết luận

      Trong hướng dẫn này, bạn đã học cách tạo các mã thông báo ERC20 này và triển khai chúng vào chuỗi khối cục bộ bằng cách sử dụng ganache, nhưng bạn có thể thử thách bản thân bằng cách triển khai nó vào mạng thử nghiệm như

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      49 hoặc thậm chí là

      //SPDX-License-Identifier: MIT
      
      pragma solidity ^0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
      
      contract MyToken is ERC20{
          //Instead of WILLIAM and BILL you can use your names to make this token your own!
          constructor (address _founder, uint256 _initialSupply) ERC20("WILLIAM","BILL"){
              _mint(_founder,_initialSupply);
          }
      }
      

      50. Bạn cũng đã học tất cả các cách khác nhau mà bạn có thể giao dịch bằng cách sử dụng mã thông báo của mình và cả cách tạo hợp đồng thông minh để giao dịch mã thông báo của bạn

      Làm cách nào để nhập Web3 bằng Python?

      Hãy cài đặt phát triển với Web3. py. .
      con trăn. Trước tiên, bạn sẽ muốn đảm bảo rằng bạn đã cài đặt một số phiên bản Python. .
      Web3. thư viện py. Bạn có thể cài đặt Web3. thư viện py với pip trong thiết bị đầu cuối của bạn như thế này. $ pip cài đặt web3
      URL RPC Infura

      Python có thể được sử dụng để phát triển Web3 không?

      Câu trả lời đơn giản cho câu hỏi nói trên là. có, bạn có thể sử dụng Python cho Web3 . Tuy nhiên, khi nói đến không gian phát triển chuỗi khối, bạn có thể muốn thành thạo các thư viện như “Web3. py”. Hơn nữa, “Web3. py” là một thư viện dựa trên Python giúp tương tác với chuỗi khối Ethereum dễ dàng hơn.

      Làm cách nào để sử dụng MetaMask trong Python?

      Cách thực hiện giao dịch từ ví ethereum trên metamask .
      Lần đầu tiên cài đặt và nhập web3 trong python. từ web3 nhập Web3
      Bây giờ hãy tạo nonce cho bạn thanh toán (Lưu ý. Nonce là một số nguyên duy nhất chỉ có thể được sử dụng một lần) nonce = w. đạo đức. getTransactionCount(tài khoản)
      Bây giờ chúng tôi sẽ xác minh tài khoản bằng cách sử dụng tổng kiểm tra

      Mô-đun Web3 nào giúp bạn chuyển đổi giữa các mệnh giá ether khác nhau?

      Bạn có thể sử dụng phương thức fromWei() để chuyển đổi số dư đó sang ether (hoặc mệnh giá khác).

Bạn đang tìm hiểu bài viết Chuyển mã thông báo bằng web3 python 2024


HỆ THỐNG CỬA HÀNG TRÙM SỈ QUẢNG CHÂU

Điện thoại: 092.484.9483

Zalo: 092.484.9483

Facebookhttps://facebook.com/giatlathuhuongcom/

WebsiteTrumsiquangchau.com

Địa chỉ: Ngõ 346 Nam Dư, Trần Phú, Hoàng Mai, Hà Nội.