Geth 설치 및 이용법

Words
380
Reading
2 min
Listen
Play
8y

Geth 설치 및 이용법

Geth 설치

brew install go
brew install geth

Geth 실행 (Bash)

geth --identity "ysChain" --rpc --rpcport "8800" --rpccorsdomain "*" --datadir "/Users/yskim/Documents/p2p/privatechain" --port "30303" --nodiscover --rpcapi "db, eth, net, personal, web3" --networkid 2018 console

Geth 실행취소

pkill -INT geth

Geth GenesisBlock 생성

{
       "config":{
               "chainId":15,
               "homesteadBlock":0,
               "eip155Block":0,
               "eip158Block":0
       },
       "difficulty":"200",
       "gasLimit": "2100000",
       "alloc":{
               "0x5be137d93952412083f4a944e82c696360587be4": {
                       "balance":"300000000000000000000"
               }
       }
}
$ geth --datadir /Users/ysKim/Documents/p2p/privatechain init CustomGenesis.json 

Fatal: Failed to open database: resource temporarily unavailable

현재 데몬상태로 geth가 돌아가고 있는 상태, rpc 명령를 받을을 수 없기때문에 종료 시키고 돌려야 한다.

pkill -INT geth

Fatal: Failed to write genesis block: database already contains an incompatible genesis block

rm -rf chainblock

이전에 geth를 돌려서 chain block 에 이미 다른 genesisblock이 존재하고 있는 상태, chainblock을 날려줘서 새로운 Genesis block을 만들수 있는 상태로 돌려놓아야한다.

서순서순!

Geth 명령어 (javascript)

> personal.newAccount("ysKim")                  //계좌 생성
> personal.newAccount('wsJoe')

> eth.accounts                                  //계좌 정보 조회

> miner.setEtherbase(personal.listAccounts[0])  // 마이닝으로 보상받을 이더베이스 설정

> miner.start(2)                                // 마이닝 시작 (쓰레드 개수 : 2)

> eth.getBalance(eth.accounts[0])               // 첫번째 계정의 잔액 조회

> eth.blockNumber                               // 생성된 블록의 수 조회

> eth.sendTransaction({from: eth.accounts[0],
                     to: eth.accounts[1],
                     value:web3.toWei(1,"ether")})
                                               // 1 'ether' 송금하기

> eth.sendTransaction({
   from: eth.accounts[0],
   to: eth.accounts[1],
   value: web3.toWei(2, "ether"),
   gasPrice: 20000000000,
   gasLimit:20000000
});


> personal.unlockAccount(eth.accounts[0])
                                               // 계좌 언락 (계좌 생성시 쓰인 이름 필요)

> personal.listWallet[0].status                 // 계좌 락/언락 상태 확인

> eth.pendingTransactions                       // 미확정 트랜잭션 확인

> eth.coinbase                                  // coinbase 확인

> debug.traceTransaction("0xefd4680d965c765a1bf323b89c0f30ac49a49ec03963aa5d28eda19d3f0311b8")

Commit new mining work

The message commit new work on block is displayed by geth when geth (and ethminerwhen GPU mining) is ready to start a new set of mining computations to find a nonce that matches the target.When a new block is found by your miner, or another miner on the Ethereum network , geth stops the current mining computations it is performing.geth then prepares a fresh new block, built upon the block hash of the newly received block (new parent) and the following data:

  • Transactions from the transaction pool to be included in the new block
  • Uncle block to be included in the new block

geth then emits the message commit new work on block and starts the mining computation on this new block.This procedure results in geth always mining at the top of the blockchain.

Geth 설치 및 이용법 | Ecency