WEB3

openzeppelin ์‚ฌ์šฉํ•ด ERC20 ํ† ํฐ ๋งŒ๋“ค๊ธฐ

ํƒฑ์ ค 2023. 9. 24. 22:28

1. My_Token.sol ์ž‘์„ฑ

contracts ํด๋”์— ์ž‘์„ฑ

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20{
  uint public INITIAL_SUPPLY = 120000;

  constructor() public ERC20("My Token","MT"){
    _mint(msg.sender, INITIAL_SUPPLY);
  } // ์„œ๋กœ ๋‹ค๋ฅธ ์•”ํ˜ธํ™”ํ๊ฐ€ ์ƒ๋Œ€ ์ฒด์ธ์— ์ƒ์„ฑ๋˜๊ณ  ๊ตํ™˜๋˜๋Š” ๋ฏผํŒ… ๊ตฌํ˜„
}
  • ERC20.sol ํŒŒ์ผ ๋ถˆ๋Ÿฌ์™€์„œ _mint ๊ธฐ๋Šฅ ์ถ”๊ฐ€
  • ์ƒˆ ํ† ํฐ์„ ์ƒ์„ฑํ•˜๋Š” ์ปจํŠธ๋ž™ํŠธ ๋ฐฐํฌ ์‹œ ๋ฏธ๋ฆฌ ์ •์˜๋œ ์–‘์˜ ํ† ํฐ์„ ๋ฐœํ–‰ํ•˜๊ธฐ ์œ„ํ•ด _mint ํ•จ์ˆ˜ ํ˜ธ์ถœ

2. 3_deploy_MyToken.js ์ž‘์„ฑ

migrations ํด๋”์— ์ž‘์„ฑ

var MyToken = artifacts.require("MyToken");

module.exports = function(deployer){
    deployer.deploy(MyToken);
};

3. truffle-config ๋ณ€๊ฒฝ

์ปดํŒŒ์ผ๋Ÿฌ ๋ฒ„์ „ ๋ณ€๊ฒฝ

 

4. ๋ฐฐํฌ

ganache-cli ์‹คํ–‰

๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„์—์„œ truffle migrate --reset ์ž…๋ ฅ

MyToken ์ •๋ณด๊ฐ€ ์œ„์™€ ๊ฐ™์ด ์ƒ์„ฑ๋จ

 

5. MyEtherWallet์— ์—ฐ๊ฒฐ

migrate ํ›„ ์ƒ์„ฑ๋˜๋Š” contract address์™€ MyToken.json์—์„œ abi ๊ฐ’ ์ž…๋ ฅ ํ›„ interact

initial supply, total supply ๋“ฑ ๊ธฐ๋Šฅ ๋ฐฐํฌ ํ™•์ธ ๊ฐ€๋Šฅ

 

6. ์ƒ์„ฑํ•œ ์‚ฌ์šฉ์ž์ •์˜ ํ† ํฐ์„ MetaMask์— ์—ฐ๊ฒฐ

account ๊ณ„์ •์— ๋งž๋Š” Private Key๋กœ ๊ณ„์ • ๊ฐ€์ €์˜ค๊ธฐ (ganache-cli ์‹คํ–‰ ์‹œ ๋‚˜์˜ค๋Š” account์™€ private key)

๊ณ„์ • ๊ฐ€์ ธ์˜จ ํ›„ ํ† ํฐ ๊ฐ€์ ธ์˜ค๊ธฐ

ERC20 ํ‘œ์ค€ MyToken ์ƒ์„ฑ ์™„๋ฃŒ



https://kimsfamily.kr/327

728x90