アプリケーション開発ポータルサイト
ServerNote.NET
Amazon.co.jpでPC関連商品タイムセール開催中!
カテゴリー【仮想通貨UbuntuDebian
Ubuntu Server 21.10でイーサリアムブロックチェーン【その1】
POSTED BY
2023-03-22

イーサリアム(Ethereum)は中央サーバーおよび管理者の無いピアツーピア・ブロック・チェーン・ネットワークの1つで、ビットコインに次ぐシェア第2位の仮想通貨である。
これを手持ちのUbuntu Serverから色々操作してみて、備忘録としてまとめる。

まず、本物のイーサリアムを操作するには、世界唯一のイーサリアムブロックチェーン(メインネット)に接続してやりとりしなければいけないが、これは何をするにしてもガス代(手数料)がかかる

とてもでないがいきなりそんなことはできないので、ローカルテスト用のイーサリアムブロックチェーンを自分で立ち上げて自分だけが接続してやりとりする、ということからスタートする。

1、イーサリアムを扱うパッケージ群のインストール

イーサリアムを扱うためのパッケージはUbuntuやDebianではethereumというレポジトリ・パッケージで公式からオープンソースでまとめて提供されているので、そのレポジトリを追加して更新する。

sudo -s

add-apt-repository -y ppa:ethereum/ethereum

apt update

apt search ethereum
Sorting... Done
Full Text Search... Done
abigen-unstable/impish 1.10.17+build27721+impish amd64
  Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages.

bootnode-unstable/impish 1.10.17+build27721+impish amd64
  Ethereum bootnode.

clef-unstable/impish 1.10.17+build27721+impish amd64
  Ethereum account management tool.

ethereum-unstable/impish 1.10.17+build27721+impish amd64
  Meta-package to install geth and other tools

evm-unstable/impish 1.10.17+build27721+impish amd64
  Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode.

geth-unstable/impish 1.10.17+build27721+impish amd64
  Ethereum CLI client.

puppeth-unstable/impish 1.10.17+build27721+impish amd64
  Ethereum private network manager.

python-rlp-doc/impish 0.5.1-1.2 all
  Recursive Length Prefix (RLP) library ?? documentation

python3-pyethash/impish 0.1.27-2.1build2 amd64
  Ethash proof-of-work algorithm ?? Python 3

python3-rlp/impish 0.5.1-1.2 all

ethereum-unstableをインストールすれば良さそうだ。

apt install ethereum-unstable

メインで使うのはgethコマンドであるので、確認する。

geth --help

NAME:
   geth - the go-ethereum command line interface

   Copyright 2013-2022 The go-ethereum Authors

USAGE:
   geth [options] [command] [command options] [arguments...]

VERSION:
   1.10.17-unstable-2352c722

1.10.17が入った。

2、ローカルテスト用ブロックチェーン設定ファイル作成と初期化

本物のメインネットに接続するなら不要だが、まずローカルテストチェーンを作るので、そのための最初のブロック設定ファイルを書いて、gethで初期化を実行する。

データディレクトリの作成

eth_testなどとする。

cd
mkdir eth_test

最初のブロック設定ファイルを書く

テストブロックチェーンの最初の最初のブロックを自分で作るので、そのありかたを指示するファイルである。eth_test/genesis.jsonを作成。

vi eth_test/genesis.json

JSONgenesis.jsonGitHub Source
{
  "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

特に、

"homesteadBlock": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,

このあたりの設定がないとError: invalid opcode: SHRなどのエラーに遭遇して最初からやり直しになりかねないので注意する。

ローカルブロックチェーンの初期化

geth --datadir /home/hogeuser/eth_test init /home/hogeuser/eth_test/genesis.json

INFO [03-22|11:53:55.648] Maximum peer count                       ETH=50 LES=0 total=50
INFO [03-22|11:53:55.648] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [03-22|11:53:55.650] Set global gas cap                       cap=50,000,000
INFO [03-22|11:53:55.650] Allocated cache and file handles         database=/home/hogeuser/eth_test/geth/chaindata cache=16.00MiB handles=16
INFO [03-22|11:53:56.233] Writing custom genesis block
INFO [03-22|11:53:56.234] Persisted trie from memory database      nodes=0 size=0.00B time="8.089μs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-22|11:53:56.236] Successfully wrote genesis state         database=chaindata                            hash=7b2e8b..7e0432
INFO [03-22|11:53:56.236] Allocated cache and file handles         database=/home/hogeuser/eth_test/geth/lightchaindata cache=16.00MiB handles=16
INFO [03-22|11:53:56.249] Writing custom genesis block
INFO [03-22|11:53:56.250] Persisted trie from memory database      nodes=0 size=0.00B time="7.383μs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-22|11:53:56.250] Successfully wrote genesis state         database=lightchaindata                       hash=7b2e8b..7e0432

eth_testの下に色々できているはずである。これで下準備は完了、次回から実際にブロックチェーンを立ち上げて操作を開始する。

Ubuntu Server 21.10でイーサリアムブロックチェーン【その2】

※本記事は当サイト管理人の個人的な備忘録です。本記事の参照又は付随ソースコード利用後にいかなる損害が発生しても当サイト及び管理人は一切責任を負いません。
※本記事内容の無断転載を禁じます。
【WEBMASTER/管理人】
自営業プログラマーです。お仕事ください!
ご連絡は以下アドレスまでお願いします★

☆ServerNote.NETショッピング↓
ShoppingNote / Amazon.co.jp
☆お仲間ブログ↓
一人社長の不動産業務日誌
【キーワード検索】