Home - wogus2421/BlockChain_practice GitHub Wiki

Dapp ๊ด€๋ จํ•œ ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ(truffle ์ด์šฉํ•œ pet-shop)

  • ์กฐ๊ฑด
    • 16๋งˆ๋ฆฌ์˜ ์• ์™„๋™๋ฌผ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
    • pet shop์—์„œ ์ž…์–‘๋˜๋Š” ์• ์™„๋™๋ฌผ๊ณผ Ethereum ์ฃผ์†Œ๋ฅผ ์—ฐ๊ด€์‹œํ‚ค๋Š” Dapp์ด ๋ชฉํ‘œ์ด๋‹ค.
    • ๊ธฐ๋ณธ ์›น์‚ฌ์ดํŠธ์˜ ๊ตฌ์กฐ, style์„ ์ œ๊ณตํ•œ๋‹ค(์˜ˆ์ œ์— ๊ตฌํ˜„๋˜์–ด์žˆ๋‹ค)
    • front-end ๋กœ์ง๊ณผ smart-contract ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์™„์„ฑ๋˜๋Š” ํ˜•์‹์ด๋‹ค.

๊ฐœ๋ฐœํ™˜๊ฒฝ

  • ๋‹ค์Œ์˜ ๊ฒƒ๋“ค์€ ๊น”๋ ค์žˆ์–ด์•ผ ํ•œ๋‹ค.
    • Node.js LTS_ver, npm
    • Git
    • Truffle
    • Ganache

์‹œ์ž‘

  • tuffle์„ ์ด์šฉํ•˜์—ฌ truffle ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค

    • truffle unbox (box_name) ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒ์„ฑํ•œ๋‹ค. ์ด ๊ฒฝ์šฐ ์˜ˆ์ œ์— ํ•„์š”ํ•œ ๊ฒƒ๋“ค์ด ๊ฐ™์ด ์ƒ์„ฑ๋œ๋‹ค.
    • truffle init ์„ ํ†ตํ•˜์—ฌ truffle ๋ฐ•์Šค๋ฅผ ๋งŒ๋“ ๋‹ค(init์„ ์ด์šฉํ•  ๊ฒฝ์šฐ ๋นˆ ํ”„๋กœ์ ํŠธ๋งŒ ์ƒ์„ฑ๋œ๋‹ค)
  • ๋งŒ๋“ค์–ด์ง„ box์˜ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    • contracts/ : smart contract๋ฅผ ์œ„ํ•œ solidityํŒŒ์ผ์„ ์ €์žฅํ•˜๋Š” ์žฅ์†Œ. Migrate.sol์ด๋ผ๋Š” ํŒŒ์ผ์ด ์ด๋ฏธ ์กด์žฌํ•œ๋‹ค.
    • Migrations/ : truffle์—์„œ smart contract ๋ฐฐํฌ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์ด์šฉํ•˜๋Š” ์‹œ์Šคํ…œ. ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ถ”์ ํ•˜๋Š” ์ถ”๊ฐ€์  smart contract์ด๋‹ค
    • test/ : smart contract์˜ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ JS์™€ Solidity ๋ชจ๋‘ ๊ฐ€๋Šฅํ•˜๋‹ค.
    • truffle.js : truffle ์„ค์ •ํŒŒ์ผ

smart contract ์ž‘์„ฑ

  • ๋‹ค์Œ๊ณผ ๊ฐ™์€ Adoption.sol ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜์˜€๋‹ค.
pragma solidity ^0.4.17;
contract Adoption {
  address[16] public adopters;
  function adopt(uint petId) public returns (unit) {
    require(petId >= 0 && petId <= 15);
    adopters[petId] = msg.sender;
    return petId;
  }
  function getAdopters() public view returns (address[16]){
    return adopters;
  }
}
  • public์œผ๋กœ ์„ ์–ธํ•œ ๋ณ€์ˆ˜๋Š” ์ž๋™์œผ๋กœ getter ํ•จ์ˆ˜๋ฅผ ๊ฐ–๋Š”๋‹ค. key ๊ฐ’์„ ํ†ตํ•˜์—ฌ ๋‹จ์ผ ๋ณ€์ˆ˜์„ ์–ป์–ด์˜ฌ ์ˆ˜์žˆ๋‹ค.
  • ํ•จ์ˆ˜์— ๋Œ€ํ•œ ๊ฐ„๋žตํ•œ ์„ค๋ช…
    • ์—ฌ๊ธฐ์—” ์—†์œผ๋‚˜ ์ตœ๊ทผ์˜ ๋ฒ„์ „์—์„  ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ค ๋•Œ function Adoption() ์œผ๋กœ๋„ ๊ฐ€๋Šฅํ•˜๊ณ  constucter() ๋กœ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.
    • adopt : petId๋ฅผ ๋ฐ›์•„ ๋ถ„์–‘ํ•˜๊ณ , adopter์˜ petId ์ธ๋ฑ์Šค์— ๋ฉ”์„ธ์ง€๋ฅผ ๋ณด๋‚ธ(๊ณ„์•ฝํ•œ) ์‚ฌ๋žŒ์˜ ์ฃผ์†Œ๋ฅผ ์ €์žฅํ•˜๊ณ , ์„ฑ๊ณต์‹œ ๊ทธ petId๋ฅผ return ํ•œ๋‹ค.
    • getAdopters : ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์—†์œผ๋ฉฐ adopters ๋ผ๊ณ ํ•˜๋Š” 16๊ฐœ์งœ๋ฆฌ address ๋ฐฐ์—ด์„ returnํ•œ๋‹ค.

Solidity๋Š” ์ปดํŒŒ์ผ ๊ธฐ๋ฐ˜์˜ ์–ธ์–ด์ด๊ณ , EVM ์—์„œ ์‹คํ–‰๋˜๊ธฐ ์œ„ํ•˜์—ฌ ๋ฐ”์ดํŠธ ์ฝ”๋“œ๋กœ ์ปดํŒŒ์ผ ํ•ด์•ผํ•œ๋‹ค.

  • truffle compile ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปดํŒŒ์ผ ํ•˜๋ฉด ๋œ๋‹ค.
  • ์ปดํŒŒ์ผ ์‹œ, .\build/contracts ์— compile๋œ ์ •๋ณด๋ฅผ ๋‹ด์€ json ํŒŒ์ผ์ด ์ƒ๊ธด๋‹ค
    • ์ฝ”๋“œ๋ฅผ ๊ณ ์ณค์„ ์‹œ์—๋Š” json ํŒŒ์ผ์„ ์ง€์šฐ๊ณ  ๋‹ค์‹œ ์ปดํŒŒ์ผ ํ•˜๋„๋ก ํ•˜์ž.

migration

  • ์ปดํŒŒ์ผ์— ์„ฑ๊ณตํ•˜๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋กœ migrate ํ•ด์•ผํ•œ๋‹ค

    • migration์€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ contract state๋ฅผ ๋ณ€๊ฒฝํ•˜์—ฌ ๋‹ค์Œ state๋กœ ์ด๋™์‹œํ‚ค๋Š” script๋‹ค. ์ฒซ ๋ฒˆ ์งธ migration์€ ์ƒˆ ์ฝ”๋“œ๋ฅผ deployํ•˜๋Š” ๊ฒƒ์ด์ง€๋งŒ, ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ data๋ฅผ ์ด๋™ํ•˜๊ฑฐ๋‚˜, contract๋ฅผ ์ƒˆ๋กœ์šด ๊ฒƒ์œผ๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค.
  • migrations/ ํด๋”์— default๋กœ 1_initial_migration.js ํŒŒ์ผ์ด ์กด์žฌํ•œ๋‹ค.

    • ์ด js ํŒŒ์ผ์€ ์ดํ›„ smart contract์˜ magration์„ ๊ด€์ฐฐํ•˜๊ธฐ ์œ„ํ•˜์—ฌ Migration.sol์˜ deploy๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉฐ, ์ˆ˜์ •๋˜์ง€ ์•Š์€ contract์˜ 2์ค‘ ๋ฐฐํฌ๋ฅผ ๋ง‰๋Š”๋‹ค.
  • migrations/ ๋””๋ ‰ํ† ๋ฆฌ์— 2_deploy_contracts.jsํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค. ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

var Adoption = artifacts.require("./Adoption.sol");
moodule.exports = funtion(deployer) {
  deployer.deploy(Adoption);
}
  • ๋ธ”๋ก์ฒด์ธ์œผ๋กœ contract๋ฅผ migrate ํ•˜๊ธฐ ์ „์— ๋ธ”๋ก์ฒด์ธ์„ ์‹คํ–‰ํ•ด์•ผํ•œ๋‹ค. Ganach๋ฅผ ์ด์šฉํ•œ private net์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋ฏ€๋กœ Ganache๋ฅผ ํ‚ค๋ฉด๋œ๋‹ค.
  • truffle.js ์—์„œ Ganache๋ฅผ ์„ค์ •ํ•œ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๋กœํ•˜๋ฉด ๋œ๋‹ค.
module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    }
  }
};
  • ํ„ฐ๋ฏธ๋„์—์„œ truffle migrate ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ migration ํ•œ๋‹ค.
  • ์ดํ›„ Ganache๋ฅผ ํ†ตํ•˜์—ฌ ๋ธ”๋ก์ฒด์ธ์ด transection์„ ํ†ตํ•˜์—ฌ ๋ธ”๋ก์„ ์ƒ์„ฑํ•˜์˜€๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. ์ด migration์„ ํ†ตํ•˜์—ฌ 100์ด๋”์˜€๋˜ ๊ฒƒ์ด ์กฐ๊ธˆ ๊นŽ์ธ๋‹ค.

smart contract test

  • test๋Š” Solidity ์™€ JavaScript ๋ชจ๋‘ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • test/ ๋””๋ ‰ํ† ๋ฆฌ์— TestAdoption.sol ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค.
  • ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
pragma solidity ^0.4.17;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";

contract TestAdoption{
  Adoption adoption = Adoption(DeployedAddresses.Adoption());

  function testUserCanAdopPet() public{
    unit returnedId = adoption.adopt(8);
    unit expected = 8;
    Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded.");
  }

  function testGetAdopterAddressByPetId() public {
    address expected = this;
    address adopter = adoption.adopters(8);
    Assert.equal(adopter, expected, "Owner of pet ID 8 should be recoreded.");
  }

  function testGetAdopterAddressByPetIdInArray() public {
    address expected =this;
    address [16] memory adopters = adoption.getAdopters();
    Assertequal(adopters[8], expected, "Owner of pet ID 8 should be recorded.");
  }
}
  • imports

    • Assert.sol : ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉํ•  assertion์„ ์ œ๊ณต, global์ด๋‹ค.
    • DeployedAddresses.sol : ํ…Œ์ŠคํŠธ ์‹คํ–‰์‹œ์— ํ…Œ์ŠคํŠธํ•  contract๋ฅผ ์ƒˆ๋กœ ๋ฐฐํฌํ•œ๋‹ค. ์ด๋•Œ ๋ฐฐํฌํ•œ contract์˜ address๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์—ญํ• . ์ด๋˜ํ•œ ์ „์—ญ truffle ํŒŒ์ผ์ด๋‹ค.
    • Adoption.sol : ์šฐ๋ฆฌ๊ฐ€ ํ…Œ์ŠคํŠธํ•˜๊ณ ์ž ํ•˜๋Š” contract
  • functions

    • testUserCanAdoptPet : petId 8 ์„ ์ด์šฉํ•˜์—ฌ adopt()๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ์˜ˆ์ธก๊ฐ’์ธ 8์„ ๋”ฐ๋กœ์„ ์–ธํ•˜์—ฌ Assert๋กœ ํ™•์ธํ•œ๋‹ค.
    • testGetAdopterAddressByPetId : Adoption.sol ์—์„œ public ๋ณ€์ˆ˜ ์„ ์–ธ์œผ๋กœ ์ธํ•œ getter๋ฅผ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค.
    • testGetAdopterAddressByPetIdInArray : adopters ๋ฐฐ์—ด์— PetId 8 ์„ ์ฒซ ์ž…์–‘ํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ์•Œ๊ธฐ์— ๊ทธ contract ์ฃผ์†Œ์™€ ๋น„๊ตํ•œ๋‹ค.
      • solidity์—์„œ memory ๋Š” contract์˜ storage์— ์ €์žฅํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ์ผ์‹œ์ ์ธ ๊ฐ’ ์ €์žฅ์„ ์˜๋ฏธํ•œ๋‹ค.
  • ์ž‘์„ฑ์ด ๋๋‚ฌ๋‹ค๋ฉด, truffle test ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ test๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค.

front-end ๋งŒ๋“ค๊ธฐ

  • truffle unbox ๋ฅผ ํ†ตํ•˜์—ฌ ๋งŒ๋“  ๋””๋ ‰ํ† ๋ฆฌ์ด๋ฏ€๋กœ ์ด๋ฏธ pet shop ์˜ˆ์ œ ์ง„ํ–‰์„ ์œ„ํ•œ front-end ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋‹ค.
  • ๋ช‡๊ฐ€์ง€ ์„ค์ •๋งŒ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋ฐ”๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  1. app.js
  • src/js/app.js ํŒŒ์ผ์„ ์—ฐ๋‹ค
  • initWeb3 ํ•จ์ˆ˜์˜ ์ฝ”๋ฉ˜ํŠธ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ์„ ์ฑ„์›Œ ๋„ฃ๋Š”๋‹ค.
if(typeof web3 !== 'undefined') {
  App.wep3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
}
web3 = new Web3(App.web3provider);
  • ์ด๋ฏธ ํ™œ์„ฑํ™” ๋œ web3 ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ์žˆ์œผ๋ฉด ๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๊ณ  ์•„๋‹ˆ๋ฉด ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.
  • initContract ํ•จ์ˆ˜์˜ ์ฝ”๋ฉ˜ํŠธ๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฑ„์›Œ ๋„ฃ๋Š”๋‹ค.
$.getJSON('Adoption.json', function(data) {
  // Get necessary contract artifact file and instantiate it with truffle contract
  var AdoptionArtifact = data;
  App.contracts.Adoption = TruffleContract(AdoptionArtifact);

  // Set the provider for our contract
  App.contracts.Adoption.setProvider(App.web3Provider);

  // Use our contract to retrieve and mark the adopted pets
  return App.markAdopted();
});

  • ์ฝ”๋“œ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    • ๋จผ์ € smart contract ์˜ artifact๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. artifact๋Š” deploy๋œ address ๋ฐ ABI์™€ ๊ฐ™์€ contract์— ๋Œ€ํ•œ ์ •๋ณด์ด๋‹ค.
    • callback์— artifact ๊ฐ€ ์ƒ๊ธฐ๋ฉด TruffleContract๋กœ ์ „๋‹ฌํ•˜์—ฌ contract ์˜ instance๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
    • instanceํ™” ๋œ contract๋ฅผ ํ†ตํ•˜์—ฌ web3 provider๋ฅผ ์„ค์ •ํ•œ๋‹ค.
    • ์ด์ „์— ์ด๋ฏธ ๋ถ„์–‘๋œ pet ์ธ๊ฒฝ์šฐ์—” markAdopted๋ฅผ ์ด์šฉํ•˜์—ฌ UI ์—…๋ฐ์ดํŠธ
  • markAdopted ํ•จ์ˆ˜์— ์ฃผ์„์„ ์ œ๊ฑฐํ•˜๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฑ„์›Œ ๋„ฃ๋Š”๋‹ค.

var adoptionInstance;
App.contracts.Adoption.deployed().then(function(instance) {
  adoptionInstance = instance;
  return adoptioinInstance.getAdopters.call();
}).then(function(adopters) {
  for (i = 0; i< adopters.length; i++) {
    if(adopters[i] !== '0x0~') { // 0~ -> 0 40๊ฐœ
      $('.panel-pet').eq(i).find('button').text('Success').attr('disabled',true);
    }
  }
}).catch(function(err) {
  console.log(err.message);
});
  • ์ฝ”๋“œ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    • deploy๋œ Adoptioin contract์— ์ง„์ž…ํ•˜์—ฌ ๊ทธ instance์— getAdopters()๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
    • call() ์„ ์‚ฌ์šฉํ•˜๋ฉด transection ์—†์ด ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค ์ฆ‰, ์ด๋”๋ฅผ ์†Œ๋น„ํ•˜์ง€ ์•Š๋Š”๋‹ค.
    • getAdopters() ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ชจ๋“  ํ•ญ๋ชฉ์„ ํ™•์ธํ•œ๋‹ค. ์ด๋”๋ฆฌ์›€์€ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ๋˜์–ด์žˆ๊ธฐ์— 0์ด ์•„๋‹ˆ๋ฉด address๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š”๊ฒƒ์ด๋‹ค.
    • ์ฃผ์†Œ๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด, adopt ๋ฒ„ํŠผ์„ ๋น„ํ™œ์„ฑํ™” ํ•˜๊ณ  text๋ฅผ success๋กœ ๋ฐ”๊พธ์–ด ์ค€๋‹ค
    • ๋ชจ๋“  error๋Š” console์— ๋กœ๊น…๋œ๋‹ค.
  • ๋งˆ์ง€๋ง‰์œผ๋กœ handleAdopt ํ•จ์ˆ˜์˜ ์ฃผ์„์„ ์ง€์šฐ๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฑ„์›Œ๋„ฃ๋Š”๋‹ค

var adoptionInstance;
web3.eth.getAccounts(function(error, accounts) {
  if (error) {
    console.log(error);
  }
  var account = accounts[0];
  App.contracts.Adoption.deployed().then(function(instance) {
    adoptionInstance = instance;
    //Execute adopt as a transection by sending account
    return adoptionInstance.adopt(petId, {from: account});
  }).then(function(result) {
    return App.markAdopted();
  }).catch(function(error) {
    console.log(err.message);
  });
});
  • ์ฝ”๋“œ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค
    • web3๋ฅผ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž์˜ ๊ณ„์ •์„ ๊ฐ€์ ธ์˜จ๋‹ค. error check ํ›„ callback ์—์„œ ์ฒซ ๋ฒˆ ์งธ ๊ณ„์ •์„ ์„ ํƒํ•œ๋‹ค.
    • deploy๋œ constract๋ฅผ ๊ฐ€์ ธ์™€์„œ adoptionInstance์— ์ €์žฅ. transection์„ ๋ณด๋‚ผ ๊ฒƒ ์ด๊ธฐ ๋•Œ๋ฌธ์— from ์˜ ๊ณ„์ •์ด ํ•„์š”ํ•˜๋ฉฐ ์ด๋”๋กœ ์ง€๋ถˆํ•˜๋Š” gas ๊ฐ€ํ•„์š”ํ•˜๋‹ค. adopt ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜์—ฌ transection์„ ๋ณด๋‚ธ๋‹ค.
    • transection ์ „์†ก์˜ ๊ฒฐ๊ณผ๋Š” transection object ์ด๋‹ค. ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด markAdopted๋กœ UI๋ฅผ ๋™๊ธฐํ™”ํ•œ๋‹ค.

dapp ์‚ฌ์šฉ

  1. ๋ฉ”ํƒ€๋งˆ์Šคํฌ ์‚ฌ์šฉ
  • ๋ฉ”ํƒ€๋งˆ์Šคํฌ๋ฅผ ๋กœ๊ทธ์ธํ•œ๋‹ค
  • main network์— ์ ‘์†ํ•œ ์ƒํƒœ์—์„œ ์ปค์Šคํ…€์„ ๋ˆ„๋ฅด๊ณ , ganache์˜ ์ฃผ์†Œ(private net)์œผ๋กœ ์ ‘์†ํ•œ๋‹ค.
  • ganache์˜ ๊ณ„์ขŒ๋ฅผ importํ•˜์—ฌ ๋™๊ธฐํ™”๊ฐ€ ์ž˜ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.
  1. lite-server ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ
  • npm install lite-server -g ๋กœ ๋‹ค์šด๋ฐ›๋Š”๋‹ค
  • bs-config.jason ํŒŒ์ผ์„ ์—ด์–ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‚ด์šฉ์„ ํ™•์ธํ•œ๋‹ค.
{
  "server":{
    "baseDir": ["./src","./build/contracts"]
  }
}
  • pakage.jason ํŒŒ์ผ๋„ ํ™•์ธํ•œ๋‹ค.
"scripts": {
  "dev": "lite-server",
  "test": "echo \"Error: no test specified\" && exit 1"
},
  • ๋ชจ๋‘ ํ™•์ธํ•˜์˜€๋‹ค๋ฉด npm run dev๋กœ ์‹คํ–‰ ์‹œํ‚ฌ ์ˆ˜์žˆ๋‹ค.

์˜ค๋ฅ˜

  • ๋ฉ”ํƒ€๋งˆ์Šคํฌ ์ด์Šˆ๋กœ ์ธํ•œ ์‹คํŒจ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋‹ค
  • ๊ฐ€๋‚˜์Šˆ๋ž‘ ๋ฉ”ํƒ€๋งˆ์Šคํฌ ์—ฐ๋™ํ•  ๋•Œ ์—๋Ÿฌ๊ฐ€ ์žฆ๋‹ค............