2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ubuntu20.04 + Gethの導入手順

Posted at

ubuntu 20.04にEtherum実行環境をインストールする。Virtual Boxへの導入手順はこちらを参照されたし。
https://qiita.com/kanazwk/items/5af85437ec556e23ef40

今回の参考サイトはこちら。
https://book.ethereum-jp.net/

以下にユーザ名"kana"で実行したログをもとにまとめた。

Gethのインストール

以下のコマンドを実行し、Gethをインストールする。

Geth:Go-Ethereum。Ethereumのクライアントソフトウェア。

PPA:Personal Package Archive。デフォルトの公式リポジトリに含まれない個人アーカイブのこと。add-apt-repository -y でEthereum配布元のリポジトリを指定し、ローカルのパッケージリストに追加する。

$ sudo add-apt-repository -y ppa:ethereum/ethereum
[sudo] kana のパスワード:
ヒット:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
取得:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [263 kB]
カ荳シ倖5 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
カ荳シ倖6 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal InRelease [17.5 kB]
取得:7 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [205 kB]
取得:8 http://jp.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
取得:9 http://jp.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [1,768 B]
取得:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [24.2 kB]
取得:11 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [56.5 kB]
取得:12 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main i386 Packages [500 B]
取得:13 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 Packages [3,072 B]
取得:14 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main Translation-en [880 B]
898 kB を 3秒 で取得しました (348 kB/s)
パッケージリストを読み込んでいます... 完了
$

ローカルのパッケージリストを更新することで、インストール可能なものとしてGethが認識される。

$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
ー・牴蜑・ http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease
ー・牴蜑・ http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease
ヒット:4 http://security.ubuntu.com/ubuntu focal-security InRelease
ヒット:5 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal InRelease
パッケージリストを読み込んでいます... 完了
$

Gethのインストール。結構長いこと時間がかかる。数分程度。

$ sudo apt-get install ethereum
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libfprint-2-tod1
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  abigen bootnode clef evm geth puppeth rlpdump
以下のパッケージが新たにインストールされます:
  abigen bootnode clef ethereum evm geth puppeth rlpdump
アップグレード: 0 個、新規インストール: 8 個、削除: 0 個、保留: 0 個。
36.0 MB のアーカイブを取得する必要があります。
この操作後に追加で 127 MB のディスク容量が消費されます。
続行しますか? [Y/n] y
取得:1 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 abigen amd64 1.9.25+build24398+focal [5,451 kB]
取得:2 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 bootnode amd64 1.9.25+build24398+focal [5,285 kB]
取得:3 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 clef amd64 1.9.25+build24398+focal [8,024 kB]
46% [3 clef 7,598 kB/8,024 kB 95%]                                             225 kB/s 1分 18秒
:
thereum (1.9.25+build24398+focal) を展開しています...
rlpdump (1.9.25+build24398+focal) を設定しています ...
puppeth (1.9.25+build24398+focal) を設定しています ...
clef (1.9.25+build24398+focal) を設定しています ...
bootnode (1.9.25+build24398+focal) を設定しています ...
geth (1.9.25+build24398+focal) を設定しています ...
evm (1.9.25+build24398+focal) を設定しています ...
abigen (1.9.25+build24398+focal) を設定しています ...
ethereum (1.9.25+build24398+focal) を設定しています ...
$

gethコマンドを実行してみて、インストールされたことを確認する。

$ geth --help

パッケージの最新化

インストールしたGethパッケージを最新化する。apt-get updateでローカルのパッケージリストを最新化し、apt-get upgradeでパッケージを更新する。特に更新はなかった。

$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease
ヒット:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease
ヒット:4 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal InRelease
取得:5 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
取得:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [24.3 kB]
取得:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [56.6 kB]
190 kB を 2秒 で取得しました (81.1 kB/s)
パッケージリストを読み込んでいます... 完了
$
$ sudo apt-get upgrade
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレードパッケージを検出しています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libfprint-2-tod1
これを削除するには 'sudo apt autoremove' を利用してください。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。
$

Genesisファイルを作成する

ブロックチェーンネットワーク上の最初のBlockであるGenesisブロックの情報を記述したGenesisファイルを作成する。

$ pwd
/home/kana
$ mkdir ./eth_private_net
$ ls -ld ./eth_private_net/
drwxrwxr-x 2 kana kana 4096 12月 27 18:39 ./eth_private_net/
$ cd eth_private_net/
$ touch myGenesis.json

myGenesis.jsonファイルには下記を記述する。

myGenesis.json
{
  "config": {
    "chainId": 15
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

Genesisブロックの初期化

作成したGenesisファイルの内容で、ブロックチェーン情報を初期化する。

$ geth --datadir /home/kana/eth_private_net init /home/kana/eth_private_net/myGenesis.json
INFO [12-27|18:46:13.842] Maximum peer count                       ETH=50 LES=0 total=50
INFO [12-27|18:46:13.842] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [12-27|18:46:13.844] Set global gas cap                       cap=25000000
INFO [12-27|18:46:13.844] Allocated cache and file handles         database=/home/kana/eth_private_net/geth/chaindata cache=16.00MiB handles=16
INFO [12-27|18:46:13.855] Writing custom genesis block
INFO [12-27|18:46:13.855] Persisted trie from memory database      nodes=0 size=0.00B time="13.035 μs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [12-27|18:46:13.856] Successfully wrote genesis state         database=chaindata hash="7b2e8b …7e0432"
INFO [12-27|18:46:13.856] Allocated cache and file handles         database=/home/kana/eth_private_net/geth/lightchaindata cache=16.00MiB handles=16
INFO [12-27|18:46:13.864] Writing custom genesis block
INFO [12-27|18:46:13.865] Persisted trie from memory database      nodes=0 size=0.00B time="6.663μs"  gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [12-27|18:46:13.866] Successfully wrote genesis state         database=lightchaindata hash="7b2e8b…7e0432"

--datadirで指定したディレクトリ配下にデータが格納される。下記のようなディレクトリ構成が自動生成された。

$ ls -lR eth_private_net/
eth_private_net/:
合計 12
drwx------ 4 kana kana 4096 12月 27 18:46 geth
drwx------ 2 kana kana 4096 12月 27 18:46 keystore
-rw-rw-r-- 1 kana kana  411 12月 27 18:41 myGenesis.json

eth_private_net/geth:
合計 12
-rw-r--r-- 1 kana kana    0 12月 27 18:46 LOCK
drwxr-xr-x 2 kana kana 4096 12月 27 18:46 chaindata
drwxr-xr-x 2 kana kana 4096 12月 27 18:46 lightchaindata
-rw------- 1 kana kana   64 12月 27 18:46 nodekey

eth_private_net/geth/chaindata:
合計 16
-rw-r--r-- 1 kana kana 1245 12月 27 18:46 000001.log
-rw-r--r-- 1 kana kana   16 12月 27 18:46 CURRENT
-rw-r--r-- 1 kana kana    0 12月 27 18:46 LOCK
-rw-r--r-- 1 kana kana  435 12月 27 18:46 LOG
-rw-r--r-- 1 kana kana   54 12月 27 18:46 MANIFEST-000000

eth_private_net/geth/lightchaindata:
合計 16
-rw-r--r-- 1 kana kana 1245 12月 27 18:46 000001.log
-rw-r--r-- 1 kana kana   16 12月 27 18:46 CURRENT
-rw-r--r-- 1 kana kana    0 12月 27 18:46 LOCK
-rw-r--r-- 1 kana kana  435 12月 27 18:46 LOG
-rw-r--r-- 1 kana kana   54 12月 27 18:46 MANIFEST-000000

eth_private_net/keystore:
合計 0
$

Gethの起動

gethを起動する。
--networkid "15"は、同じnetworkidで起動しているノード(peer)が探しに来るという代物。デフォルトで走査に行くが、今回--nodiscoverを指定しているのでその処理は行われない。consoleでトランザクション処理を操作できるコンソールを起動することが出来る。バックグラウンドで起動しておいて、後でコンソールを起動することもできる。

$ geth --networkid "15" --nodiscover --datadir "/home/kana/eth_private_net" console 2>> /home/kana/eth_private_net/geth_err.log
Welcome to the Geth JavaScript console!

instance: Geth/v1.9.25-stable-e7872729/linux-amd64/go1.15.6
at block: 0 (Thu Jan 01 1970 09:00:00 GMT+0900 (JST))
 datadir: /home/kana/eth_private_net
 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

To exit, press ctrl-d
>

Genesisブロックの表示

Genesisブロックの内容を表示する。作成したmyGenesis.jsonの内容を読み込んでいることを確認する。

> eth.getBlock(0)
{
  difficulty: 16384,
  extraData: "0x",
  gasLimit: 134217728,
  gasUsed: 0,
  hash: "0x7b2e8be699df0d329cc74a99271ff7720e2875cd2c4dd0b419ec60d1fe7e0432",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0x3333333333333333333333333333333333333333",
  mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  nonce: "0x0000000000000042",
  number: 0,
  parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 507,
  stateRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  timestamp: 0,
  totalDifficulty: 16384,
  transactions: [],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}
>

まとめ

導入はここまで。次回はアカウント作成とマイニングをしてみる。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?