LoginSignup
10
6

More than 5 years have passed since last update.

MacでEthereumを使ってブロックチェーン入門(Go-ethereum導入編)

Last updated at Posted at 2017-12-04

Fusic Advent Calendar 2017 4日目の記事です。

今回はブロックチェーン入門記事、第一回です。

Geth(go-ethereum)のインストール

apt-getコマンドがデフォルトでMacに入っていないので、Homebrewでインストール。

$ brew tap ethereum/ethereum
$ brew install ethereum

ちなみに開発ブランチをインストールしたい場合は以下のように打つとよいらしい。

$ brew install ethereum --devel

インストール完了したら、Gethをビルドする。
ビルドにはGo言語のコンパイラが必要。入っていない方は以下のコマンドでインストール。

$ brew install go

Geth(go-ethereum)をクローン、ビルド。

$ mkdir ~/ether-practice
$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum
$ make geth

パスが通っていることを確認します。

$ which geth
/usr/local/bin/geth

これでローカルでEthereumのブロックチェーンを構築する準備が整いました。

Genesisブロックの作成、初期化

$ mkdir testnet
$ cd testnet/
$ pwd
~/ether-practice/testnet 

テストネットのディレクトリにGenesisファイルを作成します。

$ vi genesis.jsonb
{
        "config": {
                "chainID": 15,
                "homesteadBlock": 0,
                "eip155Block" :0,
                "eip158Block":0
        },
        "nonce": "0x0000000000000042",
        "maxhash": "0x00000000000000000000000000000000000000000000000000000000000000000000000",
        "difficulty": "0x00",
        "alloc": {},
        "coinbase": "0x0000000000000000000000000000000000000000",
        "timestamp": "0x00",
        "parenthash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "extraData": "0x00",
        "gasLimit": "0x1312d00"
}"

そして以下のコマンドでgethを初期化。

$ geth --datadir ~/ether-practice/testnet init ~/ether-practice/testnet/genesis.json

それではgethを起動します。

$ geth --networkid 4649 --nodiscover --maxpeers 0 --datadir ~/ether-practice/testnet console 2>> ~/ether-practice/testnet/geth.log

コンソールが起動したら成功です。

Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable/darwin-amd64/go1.9.2

>

とりあえずgethを起動するところまでできました。
次回はアカウントの作成やプライベートネットワークでのマイニング。
そしてSolidityを用いたスマートコントラクトの実装までやっていけたらと思います。

参考書籍

はじめてのブロックチェーンアプリケーション Ethereumによるスマートコントラクト開発入門

10
6
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
10
6