天天看點

從零開始建立專屬自己的以太坊安裝

安裝

  • 日期:2018-05-17
  • 作者:新溪

安裝環境說明

cat /etc/issue
Debian GNU/Linux 9 \n \l           

注: debian基本版本也可用,其他linux系統可微調後使用

Golang的安裝:

1.打開go下載下傳連結

https://golang.org/dl/

//以debian為例,安裝目前最新版本1.10.2

wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz tar -C /usr/local -xzf go1.10.2.linux-amd64.tar.gz

修改檔案

$HOME/.profile

or

/etc/profile

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

注:這兒預設的GOPATH目錄為 $HOME/go

不懂golang的同學不用在意這個

在指令行執行

go version

看到

go version go1.10.2 linux/amd64           

說明成功安裝golang

ethereum的安裝

打開ethereum的github位址

https://github.com/ethereum/go-ethereum

執行:

cd $HOME

git clone

https://github.com/ethereum/go-ethereum.git

注: 沒有git指令的,執行

apt-get install git-core

進入go-ethereum目錄後,執行

cd go-ethereum

make geth

注:上面指令隻安裝以太坊的主要指令geth

如果想安裝全部指令,使用

make all

我們這邊隻是入門,是以暫時隻關注geth

上面指令後,如果上面一切順利的話,就能得到檔案

$HOME/go-ethereum/build/bin/geth           
export PATH=$PATH:/usr/local/go/bin:$HOME/go-ethereum/build/bin           

建立并啟動自己的ethereum

mkdir $HOME/eth

cd $HOME/eth

touch init.json

vi init.json

往init.json檔案中增加如下内容

{
    "config": {   // 定義個人鍊的設定
          "chainId": 0,         // 你個人鍊的唯一辨別
          "homesteadBlock": 0,  // 定義ethereum平台的version和protocol
          "eip155Block": 0,     // 用于支援non-backward-compatible協定的改變
          "eip158Block": 0      // 
      },
    "alloc"      : {},
    "coinbase"   : "0x0000000000000000000000000000000000000000",
    "difficulty" : "0x2000",    // 挖礦難度
    "extraData"  : "",
    "gasLimit"   : "0x2fefd8",  // 燃料限制,越大限制越少
    "nonce"      : "0x0000000000000042",
    "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp"  : "0x00"
  }           

執行指令

// 初始化自己的ethereum

geth --datadir "$HOME/eth" init init.json

INFO [05-17|14:16:43] Maximum peer count                       ETH=25 LES=0 total=25
INFO [05-17|14:16:43] Allocated cache and file handles         database=/home/user/blockchain/geth/chaindata cache=16 h
andles=16
INFO [05-17|14:16:43] Writing custom genesis block 
INFO [05-17|14:16:43] Persisted trie from memory database      nodes=3 size=505.00B time=75.246µs gcnodes=0 gcsize=0.00
B gctime=0s livenodes=1 livesize=0.00B
INFO [05-17|14:16:43] Successfully wrote genesis state         database=chaindata                            hash=86c6b
a…345170
INFO [05-17|14:16:43] Allocated cache and file handles         database=/home/user/blockchain/geth/lightchaindata cache
=16 handles=16
INFO [05-17|14:16:43] Writing custom genesis block 
INFO [05-17|14:16:43] Persisted trie from memory database      nodes=3 size=505.00B time=36.625µs gcnodes=0 gcsize=0.00
B gctime=0s livenodes=1 livesize=0.00B
INFO [05-17|14:16:43] Successfully wrote genesis state         database=lightchaindata                            hash=
86c6ba…345170           
// 啟動ethereum

geth --datadir "$HOME/eth" console

INFO [05-17|14:16:59] Maximum peer count                       ETH=25 LES=0 total=25
INFO [05-17|14:16:59] Starting peer-to-peer node               instance=Geth/v1.8.8-unstable-d2fe83dc/linux-amd64/go1.1
0.2
INFO [05-17|14:16:59] Allocated cache and file handles         database=/home/user/blockchain/geth/chaindata cache=768 
handles=1024
WARN [05-17|14:16:59] Upgrading database to use lookup entries 
INFO [05-17|14:16:59] Initialised chain configuration          config="{ChainID: 0 Homestead: 0 DAO: <nil> DAOSupport: 
false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Constantinople: <nil> Engine: unknown}"
INFO [05-17|14:16:59] Disk storage enabled for ethash caches   dir=/home/user/blockchain/geth/ethash count=3
INFO [05-17|14:16:59] Disk storage enabled for ethash DAGs     dir=/home/user/.ethash                count=2
INFO [05-17|14:16:59] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [05-17|14:16:59] Loaded most recent local header          number=0 hash=86c6ba…345170 td=512
INFO [05-17|14:16:59] Loaded most recent local full block      number=0 hash=86c6ba…345170 td=512
INFO [05-17|14:16:59] Loaded most recent local fast block      number=0 hash=86c6ba…345170 td=512
INFO [05-17|14:16:59] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-17|14:16:59] Starting P2P networking 
INFO [05-17|14:16:59] Database deduplication successful        deduped=0
INFO [05-17|14:17:01] UDP listener up                          self=enode://89737c7e003fdd34383370931e2d035488fe561889a
990022f045fe079bbdf390f6788737613de98602798614bff218b4919cbf21dbde4f6674a2757f5ba5dbc@[::]:30303
INFO [05-17|14:17:01] IPC endpoint opened                      url=/home/user/blockchain/geth.ipc
INFO [05-17|14:17:01] RLPx listener up                         self=enode://89737c7e003fdd34383370931e2d035488fe561889a
990022f045fe079bbdf390f6788737613de98602798614bff218b4919cbf21dbde4f6674a2757f5ba5dbc@[::]:30303
Welcome to the Geth JavaScript console!           

看到最後的

Welcome to the Geth JavaScript console!

說明啟動成功