[LINUX] ubuntu20.04 + Geth installation procedure

Install Ethereum runtime environment on ubuntu 20.04. See here for the installation procedure for Virtual Box. https://qiita.com/kanazwk/items/5af85437ec556e23ef40

Click here for this reference site. https://book.ethereum-jp.net/

The following is a summary based on the log executed with the user name "kana".

Geth installation

Execute the following command to install Geth.

** Geth **: Go-Ethereum. Ethereum client software.

** PPA **: Personal Package Archive. A personal archive that is not included in the default official repository. Specify the Ethereum distribution source repository with add-apt-repository -y and add it to the local package list.

$ sudo add-apt-repository -y ppa:ethereum/ethereum
[sudo]kana password:
hit:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [263 kB]
Bean beans 5 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Beans 倖 6 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal InRelease [17.5 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [205 kB]
Get:8 http://jp.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:9 http://jp.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [1,768 B]
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [24.2 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [56.5 kB]
Get:12 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main i386 Packages [500 B]
Get:13 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 Packages [3,072 B]
Get:14 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main Translation-en [880 B]
Obtained 898 kB in 3 seconds(348 kB/s)
Loading the package list...Done
$

By updating the local package list, Geth will be recognized as installable.

$ sudo apt-get update
hit:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
-・ Tanka ・ http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease
-・ Tanka ・ http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease
hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
hit:5 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal InRelease
Loading the package list...Done
$

Install Geth. It takes a long time. About a few minutes.

$ sudo apt-get install ethereum
Loading the package list...Done
Creating a dependency tree
Reading status information...Done
The following packages were installed automatically but are no longer needed:
  libfprint-2-tod1
To remove this'sudo apt autoremove'Please use.
The following additional packages will be installed:
  abigen bootnode clef evm geth puppeth rlpdump
The following packages will be newly installed:
  abigen bootnode clef ethereum evm geth puppeth rlpdump
upgrade:0 pieces, new installation:8 deleted:0 pieces, pending:0 pieces.
36.I need to get a 0 MB archive.
An additional 127 MB of disk space will be consumed after this operation.
Do you want to continue? [Y/n] y
Get:1 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 abigen amd64 1.9.25+build24398+focal [5,451 kB]
Get:2 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal/main amd64 bootnode amd64 1.9.25+build24398+focal [5,285 kB]
Get: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 minute 18 seconds
:
thereum (1.9.25+build24398+focal)Is deploying...
rlpdump (1.9.25+build24398+focal)Is set...
puppeth (1.9.25+build24398+focal)Is set...
clef (1.9.25+build24398+focal)Is set...
bootnode (1.9.25+build24398+focal)Is set...
geth (1.9.25+build24398+focal)Is set...
evm (1.9.25+build24398+focal)Is set...
abigen (1.9.25+build24398+focal)Is set...
ethereum (1.9.25+build24398+focal)Is set...
$

Try running the geth command to confirm that it was installed.

$ geth --help

Package update

Update the installed Geth package. Update the local package list with apt-get update and update the packages with apt-get upgrade. There was no particular update.

$ sudo apt-get update
hit:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
hit:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease
hit:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease
hit:4 http://ppa.launchpad.net/ethereum/ethereum/ubuntu focal InRelease
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [24.3 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [56.6 kB]
Obtained 190 kB in 2 seconds(81.1 kB/s)
Loading the package list...Done
$
$ sudo apt-get upgrade
Loading the package list...Done
Creating a dependency tree
Reading status information...Done
Detecting upgrade package...Done
The following packages were installed automatically but are no longer needed:
  libfprint-2-tod1
To remove this'sudo apt autoremove'Please use.
upgrade:0 pieces, new installation:0, deleted:0 pieces, pending:0 pieces.
$

Create a Genesis file

Create a Genesis file that describes the information of the Genesis block, which is the first block on the blockchain network.

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

Describe the following in the myGenesis.json file.

myGenesis.json


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

Genesis block initialization

Initialize the blockchain information with the contents of the created Genesis file.

$ 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"

Data is stored under the directory specified by --datadir. The following directory structure was automatically generated.

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

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

eth_private_net/geth/chaindata:
16 in total
-rw-r--r--1 kana kana 1245 December 27 18:46 000001.log
-rw-r--r--1 kana kana 16 December 27 18:46 CURRENT
-rw-r--r--1 kana kana 0 December 27 18:46 LOCK
-rw-r--r--1 kana kana 435 December 27 18:46 LOG
-rw-r--r--1 kana kana 54 December 27 18:46 MANIFEST-000000

eth_private_net/geth/lightchaindata:
16 in total
-rw-r--r--1 kana kana 1245 December 27 18:46 000001.log
-rw-r--r--1 kana kana 16 December 27 18:46 CURRENT
-rw-r--r--1 kana kana 0 December 27 18:46 LOCK
-rw-r--r--1 kana kana 435 December 27 18:46 LOG
-rw-r--r--1 kana kana 54 December 27 18:46 MANIFEST-000000

eth_private_net/keystore:
Total 0
$

Launch Geth

Start geth. --networkid" 15 " is a substitute that a node (peer) running with the same networkid comes to look for it. It goes to scan by default, but since --nodiscover is specified this time, that process is not performed. You can start a console that can operate transaction processing with console. You can also start it in the background and then start the console later.

$ 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
>

View Genesis blocks

Display the contents of the Genesis block. Make sure that the contents of the created myGenesis.json are loaded.

> 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: []
}
>

Summary

This is the end of the introduction. Next time, I will try to create an account and mine.

Recommended Posts

ubuntu20.04 + Geth installation procedure
Pylearn 2 installation procedure
PostgreSQL 10.0 installation procedure
blockdiag installation procedure
Linux mint installation procedure
AWS CLI installation procedure
django-debug-toolbar installation procedure memo
Anaconda3 environment installation procedure
Scrapy environment installation procedure
MongoDB installation (Ubuntu 18 LTS)
Offline installation procedure for openpyxl
Python CMS Mezzanine installation procedure
CentOS 8 installation procedure (latest version)
Docker Easy Installation Procedure (CentOS)
Python 3.6 installation procedure [for Windows]
ubuntu 20.04 + geth environment ether remittance
OpenCV installation procedure on Raspberry Pi
PySpark 1.5.2 + Elasticsearch 2.1.0 Installation procedure and execution
Teamviewer for Linux installation procedure (CentOS)
Ubuntu 20.04 LTS installation method (for external drive)
Elasticsearch installation and basic operation for ubuntu
WSL2 (Windows Subsystem for Linux) installation procedure
Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
GPD P2 Max Ubuntu Mate installation notes