ERC20 토큰을 Astar의 테스트 네트워크로 전송합니다.
전제 조건
문서 작성자의 지식이 부족하기 때문에 때때로 잘못된 용어나 표현이 나타날 수 있으니 용서해 주십시오.
완료 코드
사전 준비
기술을 사용하다
하드하트가 뭐예요?
Hardhat은 이더 eum 소프트웨어를 컴파일하고 디버깅하는 데 사용되는 개발 환경입니다.이 외에도 Truffle Suite 등이 있습니다.
이것을 사용하면 EVM 호환성 체인을 처리할 수 있습니다.
OpenZeppelin이란?
ERC20ERC721ERC 1155 등의 코드를 간단하게 사용할 수 있는 패키지입니다.
환경 구조
릴리즈
명령하다
# 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 디렉터리에 파일을 추가합니다.
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);
}
}
● 전체적인 흐름을 알고 싶은 사람은 포장된 서류를 실제로 보라!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
프로그램 설계
1. SBY 토큰 받기
인코딩은 여기서 끝내고 디자인을 하고 싶지만 스마트 설정을 발행하려면 가스비를 지불해야 한다.
따라서 Shibuya 네트워크의 SBY를 확보해야 합니다.
다음은 공식 문서입니다.월렛에서 확인 후 계속 진행하세요.
2. 스마트 기기 발행
Solidityのコンパイル
$ npx hardhat compile
# スマコン発行 この時のアドレスはメモしておいてください
$ npx hardhat run --network shibuya scripts/deploy.js
실제 스마트 프로비저닝 발매 여부는 서비스캔에서 시부야 검색 네트워크로 확인할 수 있다.3. 프로그램 설계
npx hardhat console --network shibuya
> const ERC20 = await ethers.getContractFactory("TEST");
> const erc20 = await ERC20.attach( "発行したコントラクトアドレス" );
> await erc20.mint("あなたのウォレットアドレス", 発行したいトークンの数 );
# Ctrl + D でコンソールから退出
마지막으로 월렛에서 TEST 토큰을 확인하면 완성!최후
이 글은 프로그램을 목적으로 한 문서다.
원래 현지에서 테스트를 한 후에 개인용 컴퓨터를 발행하는 것이 비교적 보편적이다.
그러니 이 글은 참고로 사용해 주십시오.
참고 문장
Reference
이 문제에 관하여(ERC20 토큰을 Astar의 테스트 네트워크로 전송합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/yhoi/articles/5dd5b8249a0186텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)