geth 명령어 정리

숑숑·2021년 6월 30일
0

아카이빙

목록 보기
1/4

가상머신 클립보드 공유가 왜 안되는지 모르겠네여 여기 던지고 갑니다..

진행상황 요약

  • 가상머신 서버 환경설정 60% 정도? 완료
  • geth로 계정 간 송금 실험까지 성공
  • 포트만 바꿔서 오류 없이 노드 실행 확인
  • 코드 수정 없이도 똑같이 돌아가는지는 리퀘로 실험 필요

geth 실행~송금 사이클 command

  • !!!경로 고정!!!
cd C:\Users\wisep\Desktop\homerun\geth_data
  • 로그 파일 테일링
    파워쉘 키고
Get-Content "C:\Users\wisep\Desktop\homerun\geth_data\geth.log" -Wait -Tail 10

계정 생성 1 (잔액 넣고 시작)

geth account new --datadir .

-> address 획득. -> genesis.json의 alloc 필드 아래에 address,balance 형식 맞춰 지정
-> geth 재시작 -> eth.accounts -> 지정한 address가 맞는지 확인

  • 여러개 생성할 땐 그냥 여러번 치면 됨.

geth 실행

geth.log 파일로 로그 전달 (막줄 console부터 지우면 원래대로 가능)

node 1

geth --networkid 8484 --nodiscover --datadir . --port 30303 --http.addr "0.0.0.0" --http --http.port 8545 --http.corsdomain "*" --http.api="eth,net,web3,personal,web3,miner,admin,debug,rpc" --allow-insecure-unlock --miner.threads 2 console 2>> geth.log

**geth.log 파일로 로그 전달되게 해놓음 (막줄 console부터 지우면 원래대로 가능)

node2

geth --networkid 8484 --nodiscover --datadir . --port 30304 --http.addr "0.0.0.0" --http --http.port 8545 --http.corsdomain "*" --http.api="eth,net,web3,personal,web3,miner,admin,debug,rpc" --allow-insecure-unlock --miner.threads 2 --ipcdisable console 2>> geth.log

geth cmd 하나 더 띄우고 싶다면

geth attach http://localhost:8546

계정 생성 2 (잔액 0으로 시작할 때)

geth 실행 후 콘솔에서

personal.newAccount("[패스워드]");

계정 조회

  • 전체 계정 (인덱스로 각각 접근 가능)
eth.accounts;
  • 채굴보상 획득 계정
eth.coinbase;

채굴

  • 시작
miner.start();
  • 멈춤
miner.stop();

잔액 확인

  • Wei 단위
eth.getBalance(주소)
  • Ether 단위
web3.fromWei(eth.getBalance(주소), 'ether')

송금

트랜잭션 생성 전 계정 잠금해제 필수

personal.unlockAccount(주소);
eth.sendTransaction({from: 계정1, to: 계정2, value: web3.toWei(얼마, "ether")});
  • transaction ID 리턴해줌 (처음엔 pending 상태, 채굴 완료되어야 송금됨)

채굴 기다리는 transaction 확인

eth.pendingTransaction;

블록체인 reset

먼저 geth_data/geth/chaindata - 내부 파일 전체 수동 삭제

geth --datadir geth_data removedb;
geth --datadir . init genesis.json;

이거 엄청 많이 꼬였었는데 그래도 잘 안되면
C:\Users\wisep\AppData\Local\Ethereum\geth\chain_data <- 내부 파일 모두 삭제
최후의 수단은 geth_data 폴더 전체 삭제하고 다시 geth init..

profile
툴 만들기 좋아하는 삽질 전문(...) 주니어 백엔드 개발자입니다.

0개의 댓글