[๊ฐ๋จํ Geth ์ค์น ๋ฐ ํ๊ฒฝ์ค์ ์ ์ด์ ํฌ์คํธ ์ฐธ๊ณ
https://steemit.com/gcp/@bluezoid/gcp-geth]
1 ๊ฐ๋ฐ ๋๋ ํ ๋ฆฌ ์์ฑ
$mkdir ~/data_testnet
2 genesis.json ํ์ผ ์์ฑ
$cd ~/data_testnet
$vi genesis.json
์ ๋ ์๋์ ๊ฐ์ ๋ด์ฉ์ genesis.json ํ์ผ ์์ฑํจ
{
"config": {
"chainId": 33,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000033",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x100",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {}
}
3 geth ์ด๊ธฐํ
$geth --datadir /home/devno3kaul/data_testnet init /home/devno3kaul/data_testnet/genesis.json
4 geth ๊ตฌ๋(์คํ)
$geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/devno3kaul/data_testnet console 2>> /home/devno3kaul/data_testnet/geth.log
๋ค์๊ณผ ๊ฐ์ด ์คํ๋จ
5 EOA(Externally Owned Account):์ก๊ธ๋ฐ๊ณ์ฝ์คํ๊ฐ๋ฅ๊ณ์ ์์ฑ
>personal.newAccount("pass0")
"0xead06f7ce504d82837e3241394f5498cfa3df00b"
>personal.newAccount("pass1")
"0x24e73a3457a05b6910cd6078828d916ee159cc95"
==> ํจ์ค์๋ ๊ผญ ๊ธฐ์ตํ ๊ฒ, ์์์๋ ๋๊ณ์ EOA๊ณ์ ์ ์์ฑํจ
6 geth ์ข
๋ฃ
>exit
7 ์์์ EOA ์์ฑ
$geth --datadir /home/devno3kaul/data_testnet account new
INFO [04-24|05:14:05] Maximum peer count ETH=25 LES=0 total=25
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: pass2
Repeat passphrase: pass2
Address: {79e122c5ade724ceeeba1c58eb2b403f39f5484b}
8 ์์์ EOA ํ์ธ
$geth --datadir /home/devno3kaul/data_testnet account list
9 ์ก๊ธ ํ ์คํธ๋ฅผ ์ํด Ether๊ฐ ํ์ํ๊ณ Ether๋ฅผ ์ป๊ธฐ ์ํด ์ฑ๊ตด์ด ํ์ํจ, ์ฑ๊ตด์ ํด๋ณด์
10 ์ก๊ธ์ ์ํด ๊ณ์ unlock
>personal.unlockAccount(eth.accounts[0])
>personal.unlockAccount(eth.accounts[0], "pass0") : ํจ์ค์๋ ํจ๊ป
>personal.unlockAccount(eth.accounts[0], "pass0", 0) : unlock์๊ฐ, 0์ธ๊ฒฝ์ฐ Geth ์ข
๋ฃ์๊น์ง
11 Ether ์ก๊ธ
>eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(10,"ether")})
>eth.sendTransaction({from:eth.accounts[1] to:eth.accounts[2], value:web3.toWei(5,"ether")})
12 Geth ๊ธฐ๋์ HTTP-RPC ํ์ฑํ ๋ฐ ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํ
$nohup geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/devno3kaul/data_testnet --mine -minerthreads 1 --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpccorsdomain "*" --rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" 2>> /home/devno3kaul/data_testnet/geth.log &
12-1 Geth ๊ธฐ๋์ HTTP-RPC ํ์ฑํ ๋ฐ ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํ ๋ง์ด๋์ต์
๋นผ๊ณ
$nohup geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/devno3kaul/data_testnet --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpccorsdomain "*" --rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" 2>> /home/devno3kaul/data_testnet/geth.log &
13 json-rpc ๋ช
๋ น ์ํ , ์๊ฒฉ์ ์ํด์ ๋ช
๋ น์ด ์คํํ ์ ์์
$curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_listAccounts","params":[],"id":10}' localhost:8545
$curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"personal_listAccounts","params":[],"id":10}' localhost:8545
$curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_mining","params":[],"id":10}' localhost:8545
14 ์คํ๋ Geth์ rpc๋ฅผ ํตํด Geth ์ฝ์์ ์ ๊ทผํ๊ธฐ
$geth attach rpc:http://localhost:8545