라이브러리 설치

sudo apt-get install -y build-essential libgmp3-dev golang git tree

Geth

Geth는 go로 만들어진 이더리움의 노드 관련 코어이다. 코어는 여러 언어로 개발되어있는데 go로 만들어진 것을 보통 많이쓴다고 한다. 실제 프로젝트에서는 안정화의 이유 등으로 Parity를 더 많이 쓴다고 한다 (참고).

설치

cd
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum/
git checkout refs/tags/v1.5.5
make geth
./build/bin/geth version
sudo cp build/bin/geth /usr/local/bin/
which geth

데이터 디렉토리 준비

mkdir ~/data_testnet

Genesis 파일

Genesis 파일이 같으면 같은 코인으로 인식하여 별도의 코인을 생성하거나 테스트라면 이 파일을 수정하여 블록을 변경하여야 한다.

  • cd data_testnet/
  • vi genesis.json
    {
    	"nonce": "0x0000000000000042",
    	"timestamp": "0x0",
    	"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    	"extraData": "0x0",
    	"gasLimit": "0x8000000",
    	"difficulty": "0x4000",
    	"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    	"coinbase": "0x3333333333333333333333333333333333333333",
    	"alloc": {}
    }

Geth 콘솔

초기화

geth --datadir /home/eth/data_testnet init /home/eth/data_testnet/genesis.json
cd
tree data_testnet/

실행

geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/eth/data_testnet console 2>> /home/eth/data_testnet/geth.log

계정 생성

personal.newAccount("pass0")
personal.newAccount("pass1")

계정 확인

eth.accounts
eth.accounts[0]
eth.accounts[1]

Geth 콘솔 종료

exit

Geth 명령으로 계정 생성

geth --datadir /home/eth/data_testnet account new

Geth 명령으로 계정 확인

geth --datadir /home/eth/data_testnet account list

Geth 실행

geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/eth/data_testnet console 2>> /home/eth/data_testnet/geth.log

계정 확인

eth.accounts

Etherbase 확인

eth.coinbase

Etherbase 변경

miner.setEtherbase(eth.accounts[1])

Etherbase 확인 및 반환

eth.coinbase
miner.setEtherbase(eth.accounts[0])
eth.coinbase

계정 잔고 확인

eth.getBalance(eth.accounts[0])
eth.getBalance(eth.accounts[1])
eth.getBalance(eth.accounts[2])

블록 번호 확인

채굴이 되면 블록번호가 증가한다. 블록에 거래도 기록되기 때문에 보통 블록은 거래정보가 있어야 생성된다고 생각할 수도 있는데 블록생성시간이 지나도 거래가 없다면 그냥 빈 거래의 블록이 생성된다고 한다.

eth.blockNumber

채굴 개시

miner.start(1)

채굴 중 확인

eth.mining

Hashrate 확인

eth.hashrate

채굴 정지

miner.stop()

Etherbase 잔고 확인

eth.getBalance(eth.coinbase)

계정 잔고 확인

eth.getBalance(eth.accounts[0])
eth.getBalance(eth.accounts[1])
eth.getBalance(eth.accounts[2])

web3을 이용한 잔고 확인

web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
web3.fromWei(eth.getBalance(eth.accounts[2]), "ether")

송금

eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")})

잠금 해제

personal.unlockAccount(eth.accounts[0])
personal.unlockAccount(eth.accounts[0], "pass0")
personal.unlockAccount(eth.accounts[0], "pass0", 0)

처리 대기 중인 트랜잭션 확인

eth.pendingTransactions

잔고 확인

web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")

송금

eth.sendTransaction({from: eth.accounts[1], to: eth.accounts[2], value: web3.toWei(5, "ether")})

잔고 확인

web3.fromWei(eth.getBalance(eth.accounts[2]), "ether")
web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")

백그라운드로 Geth 실행

nohup geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/eth/data_testnet --mine --minerthreads 1 --rpc 2>> /home/eth/data_testnet/geth.log &

Geth 콘솔에 접속

geth attach rpc:http://localhost:8545

백그라운드로 Geth 실행(JSON-RPC)

nohup geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/eth/data_testnet --mine --minerthreads 1 --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpccorsdomain "*" --rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" 2>> /home/eth/data_testnet/geth.log &