Go-Ethereum CLI 활용

ITmakesmeSoft·2023년 3월 5일
0

BLOCKCHAIN

목록 보기
3/4

1. Go-Ethereum(Geth)이란?

"Geth (go-ethereum) is a Go implementation of Ethereum - a gateway into the decentralized web.
Geth is an Ethereum execution client meaning it handles transactions, deployment and execution of smart contracts and contains an embedded computer known as the Ethereum Virtual Machine."

Geth란 Go-Ethereum의 준말로, 프로그래밍 언어인 고(Go)에서 구현된 전체 이더넷 노드를 실행하기 위한 다목적 명령 줄 도구이다.

Geth를 처음 시작하면 네트워크 내의 다른 이더리움 클라이언트(node)에 연결하는 작업을 진행하고, 블록체인의 전체 사본을 내려받음.
Geth는 블록체인의 복사본을 최신 상태로 유지하기 위해 끊임없이 다른 노드와 통신한다. Geth는 블록을 채굴하거나, 블록체인에 트랜잭션을 추가하고 블록의 트랜잭션을 검증하며 트랜잭션을 실행할 수도 있다.
또한, RPC를 통해 상호작용할 수 있는 API를 노출하여 서버 역할을 하기도 한다.


2. 노드별 Geth 설정

1. 노드별 Geth 정보 명세

Hostnameeth0eth1
Port3030330303
Maxpeers22
Datadir~/dev/eth_localdata~/dev/eth_localdata
RPC Port85458545
RPC Addr0.0.0.0localhost
RPC API사용N/A (not available)
MiningTrueTrue

2. 각 노드별 Geth 설정 명령어

  • --datadir : 데이터 디렉터리 지정
  • --networkid : 네트워크 식별자
  • http.port : Port 지정. (``의 경우 전체 허용)*
  • http.corsdomain : Cors 지정. (``의 경우 전체 허용)*
  • http.api : Geth API 지정. (``의 경우 전체 허용)*
  • --nodiscover : 생성자의 노드를 다른 노드에서 검색할 수 없게 함. 즉 같은 제네시스 블록과 네트워크 ID에 있는 블록들이 연결되는 것을 방지
  • allow-insecure-unlock : 보안상의 이유로 외부에서 계정을 unlock하는 것을 금지하지만, 이를 허용하도록 함
  • --miner.threads : mining을 할 때 사용할 threads 수를 지정
  • console : 콘솔 구동

eth0 노드 설정

  • eth0에 접속한 상태에서 진행 접속이 안되어 있는 경우 vagrant ssh eth0 입력 후 노드 접속
  • 아래의 명령어를 입력하여 eth0 노드 설정 명령어 입력
geth \
--networkid 921 \
--datadir ~/dev/eth_localdata \
--maxpeers 2 \
--port 30303 \
--http \
--http.port "8545" \
--http.addr "0.0.0.0" \
--http.corsdomain "*" \
--http.api "eth, net, web3, miner, debug, personal, rpc" \
--allow-insecure-unlock \
--nodiscover \
console

eth1 노드 설정

  • cmd창을 하나 더 실행하여 vagrant가 init된 경로로 이동
  • vagrant ssh eth1를 입력하여 eth1 노드에 접속
  • 아래의 명령어를 입력하여 eth1 노드 설정 명령어 입력
    geth --networkid 921 --maxpeers 2 --datadir ~/dev/eth_localdata --allow-insecure-unlock --port 30303 --http --http.port 8545 --http.addr localhost --http.corsdomain "*" --miner.threads 1

3. Geth에 접근하기

geth attach <url> 명령을 통해 접근

eth0 노드 접근

geth attach http://0.0.0.0:8545

eth1 노드 접근

geth attach http://localhost:8545

[연재] geth로 private network 구성하기 - rpc 서비스 :: BlockChain.Dev

profile
💎 Daniel LEE | SSAFY 8th

0개의 댓글