๐Ÿ’ป/๋ธ”๋ก์ฒด์ธ

[๋ธ”๋ก์ฒด์ธ] Windows ํ™˜๊ฒฝ์—์„œ Ganache ๋„คํŠธ์›Œํฌ ํ…Œ์ŠคํŠธ

ruhz 2022. 8. 30. 01:16

Ganache?

Ganache๋Š” ๊ฐ„์ด ์ด๋”๋ฆฌ์›€ ๋ธ”๋ก์ฒด์ธ์ด๋‹ค. Ganache๋ฅผ ์„ค์น˜ํ•˜๋ฉด, ๋กœ์ปฌ์—์„œ ๋ธ”๋ก์ฒด์ธ ๋„คํŠธ์›Œํฌ๊ฐ€ ๊ตฌ์„ฑ๋˜๊ณ , 100ETH๋ฅผ ๊ฐ€์ง„ 10๊ฐœ์˜ ํ…Œ์ŠคํŠธ ๊ณ„์ •์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. ๊ฐœ๋ฐœ ์‹œ์— ๋น ๋ฅด๊ฒŒ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ฉ”๋ชจ๋ฆฌ ๋‚ด ๋ธ”๋ก์ฒด์ธ์ด๊ธฐ ๋•Œ๋ฌธ์— ํŠธ๋žœ์žญ์…˜ ํ…Œ์ŠคํŠธ ์‹œ ์‹ค์ œ ๋ธ”๋ก์ฒด์ธ ๋„คํŠธ์›Œํฌ์— ๋ฐฐํฌํ•˜๋Š” ๊ฒฝ์šฐ ๋ณด๋‹ค ์‹œ๊ฐ„์„ ํ›จ์”ฌ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Ganache - Truffle Suite

Features VISUAL MNEMONIC & ACCOUNT INFO Quickly see the current status of all accounts, including their addresses, private keys, transactions and balances.

trufflesuite.com

 

 

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

windows(chocolatey), git, golang, ganache-cli, geth, metamask

 

0. chocolatey(Powershell)๋กœ ๋‹ค์Œ ์ค‘ ์—†๋Š” ๊ฒƒ๋“ค์„ ์„ค์น˜ํ•œ๋‹ค.

choco install git -y
choco install golang -y
choco install mingw -y
choco install nodejs-lts

1. npm์œผ๋กœ ganache-cli ๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

npm install -g ganache-cli

2. git์œผ๋กœ go-ethereum์„ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๊ฐ€์ ธ์™€ geth์„ ์„ค์น˜ํ•œ๋‹ค.

mkdir src\github.com\ethereum\go-ethereum
git clone https://github.com/ethereum/go-ethereum --branch v1.9.24 src\github.com\ethereum\go-ethereum
cd src\github.com\ethereum\go-ethereum
go install -v ./cmd/...

3. chrome ๋ธŒ๋ผ์šฐ์ €์— metamask๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

MetaMask

๋ธŒ๋ผ์šฐ์ €์˜ ์ด๋”๋ฆฌ์›€ ์ง€๊ฐ‘

chrome.google.com

 

 

Ganache ๋„คํŠธ์›Œํฌ ๊ตฌ๋™ํ•˜๊ธฐ 

// ์ž…๋ ฅ ํ›„ ํ˜„์žฌ ์ฐฝ์€ ์œ ์ง€ํ•ด์ค€๋‹ค.
ganache-cli -d -m -p 7545 -a 5
  • -d -m : HD Wallet ์ƒ์„ฑ ์‹œ ๋‹ˆ๋ชจ๋‹‰ ๊ตฌ๋ฌธ ์‚ฌ์šฉ
  • -p ํฌํŠธ ์ง€์ • (default๋Š” 8545)
  • -a ๊ตฌ๋™ ์‹œ ์ƒ์„ฑํ•  ๊ณ„์ • ์ˆ˜ (default๋Š” 10)

 

 

ganache + geth

geth attach http://localhost:7545

geth ํด๋ผ์ด์–ธํŠธ๋ฅผ ganache ๋„คํŠธ์›Œํฌ์— ๋ถ™์—ฌ์ค€๋‹ค. JSON-RPC๋กœ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

* ์ด๋”๋ฅผ ๋ณด๋‚ด๋ณด์ž!

ํ˜„์žฌ ๋„คํŠธ์›Œํฌ์˜ ๊ณ„์ •๋“ค์„ ํ™•์ธํ•œ๋‹ค.
0๋ฒˆ ๊ณ„์ •์˜ ์ž”๊ณ ๋ฅผ ํ™•์ธํ•œ๋‹ค.
ํŠธ๋žœ์žญ์…˜์˜ ๋‚ด์šฉ์„ JSON์— ๋‹ด๋Š”๋‹ค.
ํŠธ๋žœ์žญ์…˜์„ ์‹คํ–‰ํ•œ๋‹ค.
1๋ฒˆ ๊ณ„์ •์˜ ์ด๋”๊ฐ€ 0๋ฒˆ ๊ณ„์ •์œผ๋กœ ์˜ฎ๊ฒจ์กŒ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

 

* ๋ฉ”์„ธ์ง€๋ฅผ ๋ณด๋‚ด๋ณด์ž!

 

web3.eth — web3.js 1.0.0 documentation

The web3-eth package allows you to interact with an Ethereum blockchain and Ethereum smart contracts. Note on checksum addresses All Ethereum addresses returned by functions of this package are returned as checksum addresses. This means some letters are up

web3js.readthedocs.io

 

ํŠธ๋žœ์žญ์…˜ ์–ด๋””์— ๋ฉ”์„ธ์ง€๋ฅผ ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ์„๊นŒ documentation์„ ์ฐพ์•„๋ดค๋”๋‹ˆ ABI byte string ํ˜•์‹์œผ๋กœ ๋‹ด์œผ๋ฉด data์— ๋ฉ”์„ธ์ง€๋ฅผ ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค! ABI(Application Binary Interface)๋Š” ๋ธ”๋ก์ฒด์ธ์—์„œ ์ƒํ˜ธ ์ž‘์šฉ์„ ์œ„ํ•œ ์ด๋”๋ฆฌ์›€ ์ƒํƒœ๊ณ„์˜ ํ‘œ์ค€ ์ž๋ฃŒํ˜•์ด๋‹ค. string ์ž๋ฃŒํ˜•์„ web3์˜ fromAscii(), toAscii()๋ฅผ ์ด์šฉํ•ด ๋ณ€ํ™˜ํ•˜์ž.

 

data์—๋Š” ๋ฉ”์„ธ์ง€๋‚˜ ํ•จ์ˆ˜ ๋“ฑ์„ ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.
ํŠธ๋žœ์žญ์…˜์„ ์‹คํ–‰ํ•œ๋‹ค.
๋ฐœํ–‰๋œ ํŠธ๋žœ์žญ์…˜์„ ์กฐํšŒํ•œ๋‹ค.
ํ•ด๋‹น ํŠธ๋žœ์žญ์…˜์˜ input์— ๋‹ด๊ธด ๋ฌธ์ž์—ด์„ ํ™•์ธํ•œ๋‹ค.