프라이빗 이더리움 네트워크 구축 및 마이닝

2021. 9. 1. 21:00공부/블록체인

반응형

1. Genesis Block 만들기

genesis.json 파일은 프라이빗 네트워크의 환경설정과 같다. genesis.json에는 네 가지 필드(config, difficulty, gasLimit, alloc)가 반드시 들어가야 한다.

vi genesis.json

#genesis.json
{
        "config": {
                  "chainId": 1337,
                  "homesteadBlock": 0,
                  "eip150Block": 0,
                  "eip155Block": 0,
                  "eip158Block": 0                                                                                                        
        },
        "nonce": "0xdeadbeefdeadbeef",
        "gasLimit": "9999999",
        "difficulty": "0x10",
        "alloc": {}
}

#vi 편집기
#저장 esc -> :w
#종료 esc -> :q
  • chainId : 현재 chain을 구별하는 값. replay attack으로부터 보호해주는 역할.
  • gasLimit : Gas한도
  • difficulty : nonce값을 찾기 위한 난이도. 높을수록 블록 생성 속도가 느려진다.
  • alloc : 마이닝을 하지 않아도 특정 계좌에 이더를 미리 할당
  • homesteadBlock : 블록체인의 Release버전
  • nonce : 작업 증명 시 사용되는 nonce값

2. 새로운 계좌 생성

geth 서버 경로에 새 계정을 생성한다.

geth --datadir ~/dev/eth_localdata account new

명령어 입력 후 비밀번호 설정.

계정 기억해두기

+) genesis.json 파일 수정

alloc값이나 coinbase설정을 위해 genesis.json파일을 수정할 수 있다.

3. genesis.json로 geth초기화

geth –-datadir ~/dev/eth_localdata init ~/genesis.json

4. Geth설정 및 네트워크 실행

#eth0
geth --networkid 921 --datadir ~/dev/eth_localdata --maxpeers 2 --port 30303 --rpc --rpcport "8545" --rpcaddr "0.0.0.0" --rpccorsdomain "*" --rpcapi "eth, net, web3, miner, debug, personal, rpc" --allow-insecure-unlock --nodiscover console

#eth1
geth --networkid 921 --datadir ~/dev/eth_localdata --maxpeers 2 --port 30303 --rpc --rpcport "8545" --rpccorsdomain "*" --allow-insecure-unlock --nodiscover console

+) 계좌 생성을 이전에 안했다면 계좌 생성하기

personal.newAccount()

5. 마이닝 시작 및 종료

#마이닝 시작
miner.start()

#마이닝 종료
miner.stop()

#생성된 블럭 수 확인
eth.blockNumber

#계정 잔액 확인
eth.getBalance(eth.coinbase)

#ether로 단위 변경 후 계정 잔액 확인 
web3.fromWei(eth.getBalance(eth.coinbase), "ether")

#생성된 블록의 상세 정보 조회
eth.getBlock(블록number)
반응형

'공부 > 블록체인' 카테고리의 다른 글

노드 확인 및 메타마스크 설정하기  (0) 2021.09.03
이더리움 트랜잭션 생성  (0) 2021.09.03
이더리움 노드 구성  (0) 2021.09.01
가상 머신 구성하기  (0) 2021.09.01
이더리움이란  (0) 2021.08.25