ERC20 토큰을 Astar의 테스트 네트워크로 전송합니다.

15008 단어 SolidityHardhatethtech

전제 조건


문서 작성자의 지식이 부족하기 때문에 때때로 잘못된 용어나 표현이 나타날 수 있으니 용서해 주십시오.
완료 코드
https://github.com/yhoi/shibuya-test-token

사전 준비

  • 월렛(MetaMask 등)의 추가
  • Shibuya Network(Astar Network의 상세 내용) 추가
  • https://docs.astar.network/integration/network-details

    기술을 사용하다

  • Hardhat
  • OpenZeppalin
  • 하드하트가 뭐예요?


    Hardhat은 이더 eum 소프트웨어를 컴파일하고 디버깅하는 데 사용되는 개발 환경입니다.이 외에도 Truffle Suite 등이 있습니다.
    이것을 사용하면 EVM 호환성 체인을 처리할 수 있습니다.
    https://hardhat.org/

    OpenZeppelin이란?


    ERC20ERC721ERC 1155 등의 코드를 간단하게 사용할 수 있는 패키지입니다.
    https://docs.openzeppelin.com/

    환경 구조


    릴리즈

  • Hardhat 2.9.3
  • node v16.14.0
  • npm v8.3.1
  • 명령하다


    # npmの初期化
    $ npm init -y
    
    # hardhatのinstall
    # Create a basic sample projectを選択
    # 残りは推奨されている方を選択
    $ npx hardhat install
    
    # 必要なパッケージのインストール
    $ npm install @openzeppelin/contracts
    $ npm install dotenv
    
    # 不要なファイルの削除
    $ rm contracts/Greeter.sol
    $ rm scripts/sample-script.js
    
    

    부호화


    1. 토큰 코드 생성


    OpenZeppelin의 다음 링크에서 필요한 기능을 추가하고contracts 디렉터리에 파일을 추가합니다.
    https://docs.openzeppelin.com/contracts/4.x/wizard
    contracts/TEST.sol
    // SPDX-License-Identifier: TEST
    pragma solidity ^0.8.4;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    
    contract TEST is ERC20, Ownable {
        constructor() ERC20("TEST", "TEST") {}
    
        function mint(address to, uint256 amount) public onlyOwner {
            _mint(to, amount);
        }
    }
    
    ● 전체적인 흐름을 알고 싶은 사람은 포장된 서류를 실제로 보라!
    https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/token/ERC20/ERC20.sol
    https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/access/Ownable.sol

    2. 디버깅을 위한 코드 만들기


    scripts/deploy.js
    const hre = require("hardhat");
    
    async function main() {
      // Hardhat always runs the compile task when running scripts with its command
      // line interface.
      //
      // If this script is run directly using `node` you may want to call compile
      // manually to make sure everything is compiled
      // await hre.run('compile');
    
      // We get the contract to deploy
      const ERC20 = await hre.ethers.getContractFactory("TEST");
      const erc20 = await ERC20.deploy();
    
      await erc20.deployed();
    
      console.log("ERC20 Token deployed to:", erc20.address);
    }
    
    // We recommend this pattern to be able to use async/await everywhere
    // and properly handle errors.
    main()
      .then(() => process.exit(0))
      .catch((error) => {
        console.error(error);
        process.exit(1);
      });
    

    3. 환경 변수에 Wallet의 개인 키를 추가합니다.


    .env
    PRIVATE_KEY='あなたのWalletの秘密鍵'
    
    ※ 기밀 키, 특히 자산을 보유한 월렛의 경우 개발용 월렛을 하나 더 보유하는 것이 좋습니다.

    4.hardhat.config.js 설정


    hardhat.config.js
    require("@nomiclabs/hardhat-waffle");
    require('dotenv').config();
    
    // This is a sample Hardhat task. To learn how to create your own go to
    // https://hardhat.org/guides/create-task.html
    task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
      const accounts = await hre.ethers.getSigners();
    
      for (const account of accounts) {
        console.log(account.address);
      }
    });
    
    module.exports = {
      solidity: "0.8.4",
      networks:{
        shibuya: {
          url:"https://rpc.shibuya.astar.network:8545",
          chainId:81,
          accounts:[process.env.PRIVATE_KEY],
        }
      }
    };
    
    
    네트웍스 설정을 변경하면 지정된 EVM을 보유한 체인에서 스마트 구성을 발행할 수 있다.
    이번에 Astar의 테스트 네트워크를 처리한 Shibuya
    https://docs.astar.network/integration/network-details

    프로그램 설계


    1. SBY 토큰 받기


    인코딩은 여기서 끝내고 디자인을 하고 싶지만 스마트 설정을 발행하려면 가스비를 지불해야 한다.
    따라서 Shibuya 네트워크의 SBY를 확보해야 합니다.
    다음은 공식 문서입니다.월렛에서 확인 후 계속 진행하세요.
    https://docs.astar.network/integration/testnet-faucet

    2. 스마트 기기 발행


    Solidityのコンパイル
    $ npx hardhat compile
    
    # スマコン発行 この時のアドレスはメモしておいてください
    $ npx hardhat run --network shibuya scripts/deploy.js
    
    
    실제 스마트 프로비저닝 발매 여부는 서비스캔에서 시부야 검색 네트워크로 확인할 수 있다.
    https://www.subscan.io/

    3. 프로그램 설계


    npx hardhat console --network shibuya
    > const ERC20 = await ethers.getContractFactory("TEST");
    > const erc20 = await ERC20.attach( "発行したコントラクトアドレス" );
    > await erc20.mint("あなたのウォレットアドレス", 発行したいトークンの数 );
    
    # Ctrl + D でコンソールから退出
    
    
    마지막으로 월렛에서 TEST 토큰을 확인하면 완성!

    최후


    이 글은 프로그램을 목적으로 한 문서다.
    원래 현지에서 테스트를 한 후에 개인용 컴퓨터를 발행하는 것이 비교적 보편적이다.
    그러니 이 글은 참고로 사용해 주십시오.

    참고 문장


    https://realtakahashi-work.medium.com/hardhat-astar-network-ee2b27563a3f 사용

    좋은 웹페이지 즐겨찾기