티스토리 뷰

카테고리 없음

이더리움 개발 하기(1)

정두현의아이티세상 2019. 2. 13. 18:26

geth설치

geth는 이더리움 실행을 위한 CLI


사전 golang-go설치


# 패키지를 이용한 설치
$ sudo apt-get install golang-go
잘못 설치한경우이거나 버전이 안맞는경우
-필자의 경우는 apt-get으로 설치시 버전문제로 수동 설치하였다
$ sudo apt-get remove golang-go
바이너리를 이용한 설치
$ wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
$ tar zxvf go1.10.3.linux-amd64.tar.gz
$ cd go
$ export GOROOT=$(pwd)
$ export PATH=$PATH:$GOROOT/bin
$ go version
go version go1.10.3 linux/amd64


실제  geth 설치


$ git clone https://github.com/ethereum/go-ethereum.git
$ cd go-ethereum
$ make
$ sudo cp build/bin/geth /usr/local/bin/
$ geth version
Geth
Version: 1.8.14-unstable
Git Commit: 45eaef24319897f5b1679c9d1aa7d88702cce905
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.3
Operating System: linux
GOPATH=
GOROOT=/home/jbshin/ehtereum-workspace/go



Private network설치


$ mkdir -p ~/ethereum-workspace/privnet
$ cd ~/ethereum-workspace/privnet


채굴및 기본설정파일인 genesis..json파일

{
  "config": {
    "chainId": 2018,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000033",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x8000000",
  "difficulty": "0x100",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}



초기화


$ geth --datadir ./data init genesis.json


노드 실행


$ geth --rpc --datadir ./data --nodiscover --rpcapi db,eth,net,web3,admin.personal console


Geth사용하기


> eth.accounts
[]


계정생성

> personal.newAccount('ccc')
"Oxdlkfjapoe8iroj1239jflkdb89" # 키생성


> eth.accounts
["Oxdlkfjapoe8iroj1239jflkdb89"]


키값입력이 힘든경우 배열로 [0]로 입력가능

> eth.getBalance(eth.accounts[0]) # eth.getBalance('키값')
0



채굴 시작 - 어느정도 시간이 지나면 채굴이 된다.


> miner.start()
.
.
.
INFO [08-10|17:39:54.979] 🔨 mined potential block                  number=1 hash=5a2077…0eb665
cles=0 elapsed=316.197µs


채굴 중단은 miner.stop()


송금을 하려는데 하려면 우선 unlock해야 한다.

> personal.unlockAccount(eth.accounts[0])
Unlock account 0x12312312312378bdfh1238
Passphrase:    //여기에는 계정생성시 입력한 값을 입력('ccc')
true


unlock이 완료되면 송금을 시도한다.

-우선 계정을 하나더 생성한다.


> personal.newAccount('ddd')
"Ox123123sdkjfsdi2" # 키생성



송금을 진행하자


[0]에서 1번으로 1eth를 송금

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1, 'ether')})
INFO [08-10|19:59:50.985] Submitted transaction                    fullhash=0x1a5fa277634a504a10ff4f33a6a29c208e90c113d54b40c5b4bcc99e84fd1a63 recipient=0xc07f222C6312473FC5694fD2ae1cf1E78410b58C
"0x12312312312378bdfh1238"


채굴된 결과 확인은

>eth.getBalance(eth.accounts[10])


노드정보는


> admin.nodeInfo

{

  enode: "enode://6b98677005fa17215d9a6f00b29cc67dcc721bb21aa827df17f69c9d4a15fbcccd19bfd3daeb6787b723494aae04b2403f3a48244f74a99484edf3dfaeaebf88@127.0.0.1:30303?discport=0",

  enr: "0xf895b84058968ed044b6ccf5f23228b68cea8dc88e97e42c38062df824dd966cd462577770d4a1cc2cf43f4479507720333a345d8d390e4f9d18a7cdf6a552b27b490e640283636170ccc5836574683ec5836574683f826964827634826970847f00000189736563703235366b31a1026b98677005fa17215d9a6f00b29cc67dcc721bb21aa827df17f69c9d4a15fbcc8374637082765f",

  id: "4383d500ae0af79c5fb60223e3fdde47c7ef6a0537f7e097f9b93bdec74a1292",

  ip: "127.0.0.1",

  listenAddr: "[::]:30303",

  name: "Geth/v1.9.0-unstable-d596bea2/linux-amd64/go1.10.3",

  ports: {

    discovery: 0,

    listener: 30303

  },

  protocols: {

    eth: {

      config: {

        chainId: 2018,

        eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000",

        eip155Block: 0,

        eip158Block: 0,

        homesteadBlock: 0

      },

      difficulty: 36590273,

      genesis: "0x5704d029fe80f4fb605c0cb5e31d591511f10a46a0cb8166f97d8d559f9bc5b0",

      head: "0x59dabde05ef381897e614d62063c907bfc927b5f7fe2e6353ccbabd440360e19",

      network: 1

    }

  }

}


추가 노드 지정

> exit
$ geth --rpc --rpcaddr 0.0.0.0 --datadir ./data --nodiscover --rpcapi db,eth,net,web3,admin.personal console


다른 서버(노드)를 추가 가능


> admin.addPeer('enode://9bb90c172175f636faa6d1670607c88d23524080ee38f63a6d9347f5fa8d1e931a4a9e0423e7fab9f7816883d4a818474118aa41039e495f7f172d285d7a4df7@[::]:30303?discport=0')
true



참고: https://bum752.github.io/ethereum/geth/


댓글