본문으로 바로가기

이더리움 클라이언트 설치하기

category 이더리움/Ethereum Core 2018. 4. 2. 23:02

이더리움은 비트코인과 함께 대표적인 암호화페의 한종류로서 Smart Contract가 추가된 2세대 암호화폐입니다.

화폐기능이 주가되었던 비트코인에 비해서 프로그래밍 가능한 Smart contract기능이 추가되어 다양한 DApp 개발이 가능합니다.

geth는 이더리움의 모든 기능을 사용할수 있는 클라이언트로 설치는 바이너리를 사용하여 설치하는 방법과 소스를 빌드하여 설치하는 방법이 있습니다.

https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu


바이너리는 다음과 같이 설치할수 있습니다.


$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt-get update
$ sudo apt-get install ethereum


소스를 사용하여 빌드하는 방법은 다음 순서로 진행을 합니다. (소스 빌드는 ubuntu 환경을 기준으로 합니다)


먼저 이더리움 geth는 Go 언어로 작성이 되었기 때문에 Go lang을 설치합니다.

geth 빌드에는 go lang 버전이 1.9 이상이 필요하며, 버전 1.9.1 버전이하에서는 빌드시에 에러가 발생하기 때문에 반드시 go lang 버전이 1.9.2 이상이 필요합니다.

Go lang의 다운로드 페이지를 참고로 최신버전의 go lang을 설치하도록 합니다. (현재 최신버전 1.9.5)


$ curl -O https://storage.googleapis.com/golang/go1.9.5.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.9.5.linux-amd64.tar.gz


위와같이 실행하면 /usr/local/go 에 설치가 됩니다. (권한문제가 있는경우 sudo 로 실행합니다)

설치가 완료되면 실행경로를 추가해줍니다. (/etc/profile or $HOME/.profile)


$ export PATH=$PATH:/usr/local/go/bin
$


Go lnag 설치가 완료되었으면 다음과 같이 소스를 다운로드 받은후에 빌드를 합니다.


$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum
$ make geth


안정된 버전의 소스를 사용하기 원한다면 다음과 같이 git branch를 release branch로 변경해도 됩니다.

다음과 같이 현재 가장 최신의 release branch는 1.8로 하기와같이 1.8 branch로 변경후 빌드를 합니다.


ihpark92@ubuntu:~/go-ethereum$ git branch --all
* master
remotes/origin/HEAD -> origin/master
remotes/origin/gh-pages
remotes/origin/master
remotes/origin/poc8
remotes/origin/release/0.9.36
remotes/origin/release/1.0.0
remotes/origin/release/1.0.1
remotes/origin/release/1.1.0
remotes/origin/release/1.2.1
remotes/origin/release/1.3.0
remotes/origin/release/1.3.2
remotes/origin/release/1.3.3
remotes/origin/release/1.3.4
remotes/origin/release/1.3.5
remotes/origin/release/1.3.6
remotes/origin/release/1.4
remotes/origin/release/1.5
remotes/origin/release/1.6
remotes/origin/release/1.7
remotes/origin/release/1.8
remotes/origin/swarm
remotes/origin/verboseblockvalidation
ihpark92@ubuntu:~/go-ethereum$ git checkout remotes/origin/release/1.8
ihpark92@ubuntu:~/go-ethereum$ git checkout -b 1.8


빌드가 완료되면 하기 디렉토리에 geth 실행화일이 생성되니 .profile 에 해당 패스를 추가해주는것이 좋습니다.


$ ihpark92@ubuntu:~/go-ethereum/build/bin$ ls
$ geth
$ ihpark92@ubuntu:~/go-ethereum/build/bin$


다음과 같이 geth 버전을 확인할수 있습니다.

geth 버전은 위에서 이더리움 소스 branch를 1.8 release branch로 선택하였고, Go lang은 가장 최신의 1.9.5로 설치되어 있음을 확인할수 있습니다.


ihpark92@ubuntu:~$ geth version
Geth
Version: 1.8.3-stable
Git Commit: 329ac18ef617d0238f71637bffe78f028b0f13f7
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.5
Operating System: linux
GOPATH=/usr/local/go
GOROOT=/usr/local/go
ihpark92@ubuntu:~$


여기까지 이더리움 소스를 빌드하여 설치를 완료하였으니 이제 private net을 통해 실행을 하도록 하겠습니다.


먼저 계좌정보가 저장될 디렉토를 하나 생성하고(.data) 다음과 같이 계좌를 하나 생성하도록 하겠습니다.


ihpark92@ubuntu:~/go-ethereum/build/bin$ ./geth --datadir ./data account new
INFO [04-02|22:14:39] Maximum peer count ETH=25 LES=0 total=25
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {06bd73d04fa606e0b2da4a93adeb14b58dcfe64e}
ihpark92@ubuntu:~/go-ethereum/build/bin$


이더리움 동작을 위해서 최초 genesis block에 대한 정보가 필요합니다.

다음과 같이 CustonGenesis.json 화일을 작성하여 geth가 설치되어있는 디렉토리에 저장하도록 합니다.

하기에 마지막 alloc 부분은 위에서 생성한 지갑주소를 넣어줍니다.


{
"config": {
"chainId" : 15,
"homesteadBlock" : 0,
"eip155Block" : 0,
"eip158Block" : 0
},
"nonce" : "0x0000000000000042",
"timestamp": "0x00",
"parentHash":
"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00",
"gasLimit": "0x800000",
"difficulty": "0x400",
"mixhash":
"0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
"06bd73d04fa606e0b2da4a93adeb14b58dcfe64e": {
"balance": "10000000000000000000"
}
}
}


그리고  다음과 같이 위에서 생성한 json 화일을 저장해놓습니다.


ihpark92@ubuntu:~/go-ethereum/build/bin$ ls -la
합계 36320
drwxrwxr-x 3 ihpark92 ihpark92 4096 Apr 2 21:53 .
drwxrwxr-x 4 ihpark92 ihpark92 4096 Apr 2 21:13 ..
-rw-rw-r-- 1 ihpark92 ihpark92 566 Apr 2 21:53 CustomGenesis.json
drwxrwxr-x 2 ihpark92 ihpark92 4096 Apr 2 21:49 data
-rwxrwxr-x 1 ihpark92 ihpark92 37173632 Apr 2 21:13 geth
ihpark92@ubuntu:~/go-ethereum/build/bin$


하기에 데이타가 저장될 디렉토리 ./data를 지정하고, genegis 블록정보가 포함되어있는 CustonGenesis.json 화일을 지정하여 genesis 블록을 생성하면 private network 실행을 위한 준비가 완료됩니다.


ihpark92@ubuntu:~/go-ethereum/build/bin$ ./geth --datadir ./data init CustomGenesis.json
INFO [04-02|21:59:13] Maximum peer count ETH=25 LES=0 total=25
INFO [04-02|21:59:13] Allocated cache and file handles database=/home/ihpark92/go-ethereum/build/bin/data/geth/chaindata cache=16 handles=16
INFO [04-02|21:59:13] Writing custom genesis block
INFO [04-02|21:59:13] Persisted trie from memory database nodes=1 size=200.00B time=23.25µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [04-02|21:59:13] Successfully wrote genesis state database=chaindata hash=91e48a…cbfcc2
INFO [04-02|21:59:13] Allocated cache and file handles database=/home/ihpark92/go-ethereum/build/bin/data/geth/lightchaindata cache=16 handles=16
INFO [04-02|21:59:13] Writing custom genesis block
INFO [04-02|21:59:13] Persisted trie from memory database nodes=1 size=200.00B time=69.863µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [04-02|21:59:13] Successfully wrote genesis state database=lightchaindata hash=91e48a…cbfcc2
ihpark92@ubuntu:~/go-ethereum/build/bin$


이제 생성된 genesis 블럭과 계좌를 기반으로 private net을 실행하도록 하겠습니다.


ihpark92@ubuntu:~/go-ethereum/build/bin$ ./geth --identity "PrivateNetwork" --datadir "./data" --port "30303" --rpc --rpcaddr "127.0.0.1" --rpcport "8080" --rpccorsdomain "*" --nodiscover --networkid 1900 --nat "any" --rpcapi "db,eth,net,web3,miner" console


실행후 다음과 같이 계좌정보와 잔액조회를 해보면 genesis block에 alloc 정보에 명시한 정보가 나오는것을 확인할수 있습니다.


> eth.accounts
["0x6f45ffa37ed51bc77f7476998c3d71221240b12e"]
> eth.getBalance(eth.coinbase)
10000000000000000000
>


다음은 다음과 같이 miner.start() 명령어로 채굴을 실행해보도록 하겠습니다.


> miner.start()
INFO [04-02|22:55:39] Updated mining threads threads=0
INFO [04-02|22:55:39] Transaction pool price threshold updated price=18000000000
null
> INFO [04-02|22:55:39] Starting mining operation
INFO [04-02|22:55:39] Commit new mining work number=69 txs=0 uncles=0 elapsed=132.014µs
> INFO [04-02|22:55:39] Successfully sealed new block number=69 hash=61e6ef…61a88f
INFO [04-02|22:55:39] 🔨 mined potential block number=69 hash=61e6ef…61a88f
INFO [04-02|22:55:39] Commit new mining work number=70 txs=0 uncles=0 elapsed=120.199µs
INFO [04-02|22:55:40] Successfully sealed new block number=70 hash=81a7e6…a68b62
INFO [04-02|22:55:40] 🔨 mined potential block number=70 hash=81a7e6…a68b62
INFO [04-02|22:55:40] Commit new mining work number=71 txs=0 uncles=0 elapsed=72.851µs


채굴이 진행중일때 계좌의 잔액을 조회해보면 다음과같이 증가함을 볼수 있으며, 하기는 잔액단위를 디폴트 wei에서 ether 로 변경하여 출력하고 있습니다.

채굴을 중지하고자 할때는 miner.stop()을 실행하면 됩니다.


> eth.getBalance(eth.coinbase)
90000000000000000000
> eth.getBalance(eth.coinbase)
95000000000000000000
> web3.fromWei(eth.getBalance(eth.coinbase), "ether");
295
> web3.fromWei(eth.getBalance(eth.coinbase), "ether");
310
> web3.fromWei(eth.getBalance(eth.coinbase), "ether");
350
> web3.fromWei(eth.getBalance(eth.coinbase), "ether");
350
> web3.fromWei(eth.getBalance(eth.coinbase), "ether");


다양한 geth 명령어는 geth help 를 통해서나 다음의 페이지에서 확인할수 있습니다.


https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options

https://github.com/ethereum/go-ethereum/wiki/Management-APIs