WEB3

Private Network์— ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ ๋ฐฐํฌ

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

1. openzeppelin ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

** openzeppelin๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ: ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ ์ฝ”๋“œ๋“ค ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ

smartcontract ํด๋” ์ƒ์„ฑ ํ›„

truffle init

npm init -y

npm install -E openzeppelin-solidity

npm install @openzeppelin/contracts

2. smartcontract ํด๋”์—์„œ truffle-config.js ํŒŒ์ผ ์ˆ˜์ •

network์™€ compiler ์ˆ˜์ •

3. test.sol ํŒŒ์ผ ์ž‘์„ฑ

contract ํด๋” ์•ˆ์— test.sol ํŒŒ์ผ ์ž‘์„ฑ

pragma solidity ^0.5.2; // solidity 0.5.2 ๋ฒ„์ „์„ ์‚ฌ์šฉ

contract TEST {  // contract ์ด๋ฆ„์„ TEST๋กœ ์ง€์ •
  string public constant name = "TEST token"; // ํ† ํฐ์˜ ์ด๋ฆ„์€ TEST token
  string public constant symbol = "TEST"; // TEST๋ผ๋Š” ์ด๋ฆ„์„ ์‚ฌ์šฉ
  uint public constant decimals = 18; // ์†Œ์ˆ˜์  18์ž๋ฆฌ๊นŒ์ง€ ์‚ฌ์šฉํ•˜๊ฒ ์Œ
  uint public constant INITIAL_SUPPLY = 1000 * 10 ** decimals; // ์ดˆ๊ธฐ ๋ฐœํ–‰๋Ÿ‰์€ 1000.000000000000000000 (์†Œ์ˆ˜์  18์ž๋ฆฌ๊นŒ์ง€์‚ฌ์šฉ)
  string constant test = "You can not see this"; // public ํ‘œ์‹œ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ๋ฌธ๊ตฌ ๋ณผ ์ˆ˜ ์—†์Œ.
}

** ๋ณ€์ˆ˜ ์„ ์–ธ์‹œ public ํ•˜์ง€ ์•Š์€ test ๋ณ€์ˆ˜๋Š” ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ ๋ฐฐํฌ ํ›„์— ์ฐพ์„ ์ˆ˜ ์—†์Œ

4. ๋ฐฐํฌ ์ฝ”๋“œ ์ž‘์„ฑ

migration ํด๋” ์•ˆ์— 2_test_migration.js ํŒŒ์ผ ์ƒ์„ฑ

const TestToken = artifacts.require("./Test");

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

5. ์ปจํŠธ๋ž™ํŠธ ๋ฐฐํฌํ•˜๊ธฐ

ganache-cli ์‹คํ–‰ ํ›„

truffle migrate ์‹คํ–‰

  • ์œ„์™€ ๊ฐ™์ด 2_test_migration.js ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ ํŒŒ์ผ์ด ๋ธ”๋ก์ฒด์ธ์— ์—…๋กœ๋“œ ๋œ ๊ฒƒ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ
  • ์œ„์˜ contract address๋กœ ‘TEST’ ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ์™€ ํ†ต์‹  ๊ฐ€๋Šฅ
  • migrate ํ›„ build ํด๋” ์ƒ์„ฑ๋จ → build ํด๋” ์•ˆ์˜ TEST.json ํŒŒ์ผ ๋ณด๊ธฐ

"abi” → ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐ”์ด๋„ˆ๋ฆฌ ์ธํ„ฐํŽ˜์ด์Šค

  • ABI์—์„œ ๊ณ„์•ฝ์„ ์ •์˜ํ•˜๊ณ , ์ด ๊ณ„์•ฝํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ณ ์ž ํ•˜๋Š” ํ˜ธ์ถœ์ž๋Š” ABI๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ

“deployedBytecode” → ๊ณ„์•ฝ ๋ฐฐํฌ ์œ„ํ•ด ์ด ๋ฐ”์ดํŠธ ์ฝ”๋“œ ํ•„์š”

→ → ๊ณ„์•ฝ์˜ ๋ฐฐํฌ๋ฅผ ์œ„ํ•ด์„œ ๋ฐ”์ดํŠธ ์ฝ”๋“œ ํ•„์š”, ๊ณ„์•ฝ์˜ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•ด์„œ ABI๊ฐ€ ํ•„์š”

 

6. ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ์™€ ํ†ต์‹ ํ•˜๊ธฐ

๊ธฐ์กด์— ์„ค์น˜ํ–ˆ๋˜ myetherwallet

contract → intertact with contract

contract address → ์œ„์—์„œ migrate ๊ฒฐ๊ณผ contract address ์ž…๋ ฅ

ABI/JSON interface → TEST.json ํŒŒ์ผ์—์„œ abi ๊ฐ’ ๋ณต์‚ฌ

function ํ•˜๋‚˜์”ฉ ํด๋ฆญํ•ด๋ณด๋ฉด test.sol์—์„œ ์ž‘์„ฑํ–ˆ๋˜ ๋ณ€์ˆ˜๋“ค ํ™•์ธ ๊ฐ€๋Šฅ (name, symbol, decimal ..)

((public ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ๋ณ€์ˆ˜ test๋Š” ํ™•์ธ๋˜์ง€ ์•Š์Œ))

→ ์Šค๋งˆํŠธ์ปจํŠธ๋ž™ํŠธ์— ์ •์ƒ์ ์œผ๋กœ ๋ฐฐํฌ ํ™•์ธ



์ถœ์ฒ˜ https://kimsfamily.kr/327

728x90