How to Create Private Ethereum Blockchain using Geth
Source: 블록체인 프로젝트
Geth를 활용한 이더리움 네트워크 구축
❔geth : google에서 개발한 golang 기반으로 만들어진 이더리움 프로그램
이더리움 이미지 받기
$ docker pull pjt3591oo/ethereum-geth:1.90 #이더리움 환경이 설치된 docker image 다운받기
$ docker image # image 확인
$ docker ps -a #
이더리움 컨테이너 생성
$ docker run -it --name ethereum.geth.com -p 8545:8545 -p 30303:30303 put3591oo/ethereum-geth:1.90 /bin/bash
-
option
p : 포트 포워딩 -> 호스트 시스템으로 8545, 30303 포트 번호로 들어온 요청을 컨테이너의 8545,30303 포트 번호로 넘겨준다. 포트 포워딩 설정을 하지 않으면 해당 컨테이너를 제외한 모든 곳에서 접속할 수 없다.
Genesis block 생성
작업 디렉터리로 이동(컨테이너 실행 상태여야 함)
$ cd ~/
$ mkdir node1 #노드의 데이터를 쌓을 디렉터리를 만든다
$ cd node1
##현재 디렉터리에서 이더리움 계정 생성
$ geth --datadir [경로] account new
$PWD : 현재 디렉터리 경로
account new : 계정 생성 시 사용
비밀번호 입력하면 keystore 파일 생성 및 주소가 출력 됨. !이 주소 복사!
제네시스 파일 생성
vi genesis1.json
{
"config": {
"chainId": 190128,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" :{
"1df27f20bc3d2de6e64817fac736cb7dabea777f":{"balance":"3000000000000000000"}
},
"difficulty": "0x20000",
"gasLimit": "0x2fefd8",
"coinbase": "0x0000000000000000000000000000000000000000",
"extraData": "",
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}
alloc에 아까 복사한 주소를 넣는다. 해당 계정에 balance를 통해 이더리움을 할당할 수 있다.
제네시스 블록 생성
cd ~/
cd node1
geth --datadir [경로] init [제네시스 파일]
노드 실행
$ geth --datadir $PWD --networkid 1234 console
> eth.blockNumber #블록 개수 확인
> eth.getBlock([블록번호]) # ex) eth.getBlock(0) #블록 정보 확인
> eth.accounts #계정 확인
> eth.getBalance([지갑주소]) #계정 잔액 조회 (현재 3eth가 있어야 함)
geth --networkid 1234 --maxpeers 2 --datadir $PWD --port 30303 --rpc --rpcport 8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*" --rpcapi "admin,net,miner,eth,rpc,web3,txpool,debug,personal" --miner.threads 1 --unlock 0 --password ~/node1/passwd --verbosity
geth attach rpc:http://0.0.0.0:8545
지갑 비밀키
0x1ef661921423e529fec74675cba87f5cb8d92a19106cb748284609893bd4a7bb
지갑 주소
0xeB5279858e34486F186CBdFf03Bf49E1B079BF63
💙You need to log in to GitHub to write comments.💙