LoginSignup
2
3

More than 5 years have passed since last update.

ブロックチェーンイーサリアムチュートリアル

Last updated at Posted at 2017-11-19

Dockerでgethをインストール

1. コンテナを作成

docker run -it --name "eth" ethereum/client-go:v1.7.2

2. 必要なパッケージをインストール

apk --update add vim git

3. Defining the private genesis state (genesis.jsonファイルを下記のように作成)

$ cat /root/genesis.json

{
"nonce": "0x0000000000000000",
"timestamp": "0x00",
"difficulty": "0x10A",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00",
"alloc": {},
"gasLimit": "0x47E7C4",
"config": {
        "homesteadBlock": 0
      }
}

$ geth init /root/genesis.json

4. イーサリアムnodeを作成し、起動する

$ mkdir -p /root/gethdata

$ geth --datadir /root/gethdata --networkid 10 --nodiscover --dev --nodiscover console

説明:
- datadir: ブロックチェーンとアカウント情報が保存される場所
- dev: デバッグ用のDeveloper mode
- nodiscover: 他のネットワークに繋げないようにする
5. 対話型のコンソールでetherの操作を確認

参考:https://book.ethereum-jp.net/first_use/mining_ether.html

# アカウント作成
> personal.newAccount("hogehoge1")    ← hogehoge1はパスワードです。
"0xddf401a8396966c00dc55cd97fca979829e0107c"

> personal.newAccount("hogehoge2")
"0x7c8e10566e2581664de9183afa8cb3be83786ea0"

# アカウント一覧を確認
> eth.accounts
["0xddf401a8396966c00dc55cd97fca979829e0107c", "0x7c8e10566e2581664de9183afa8cb3be83786ea0"]

# etherbaseを確認 (etherbaseとは、各ノードで採掘を行う際にその報酬を紐づけるEOAのアドレスを示します)
> eth.coinbase
"0xddf401a8396966c00dc55cd97fca979829e0107c"

# etherbaseはデフォルトではプライマリーのアカウント(eth.accounts[0]コマンドを実行して表示されるアドレスのEOA)が設定されますが、下記のようにminer.setEtherbase(new_adress)コマンドで変更することも可能です。

> miner.setEtherbase(eth.accounts[1])
> eth.coinbase
'0x7c8e10566e2581664de9183afa8cb3be83786ea0'

# etherの採掘
> miner.start()
true

> miner.stop()
true

# 採掘状況の確認
> eth.blockNumber
145

# 報酬の確認
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
'515'

2
3
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
3