[간단한 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