LoginSignup
15
11

More than 5 years have passed since last update.

Gethのインストールから起動まで(Mac)

Posted at

はじめに

今年からブロックチェーンの勉強を始めようとしましたが、
インターネット上に中々資料が見つからない、記事が古いものが多かったので今後の人たちのために手順を書きとめていきます。
最終的にはDApps(Decentralized Application)を作成できるようになることです。
間違いあるかもしれませんのでその場合は連絡ください。できる限り対応します。

Gethとは?

Gethとはイーサリアムネットワークに接続するためのツールです。
自分自身がノードになってマイニングをしたりすることもできます。
GoLangで書かれています。

環境

  • MacOSX 10.12.6
  • Homebrew 1.4.3

Gethのインストール

ターミナルを立ち上げて以下の2つのコマンドを実行します。

インストール
$ brew tap ethereum/ethereum
$ brew install ethereum

より詳細な説明は以下のサイトを参照
https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Mac

Mac以外の人は上記サイトで別のOSのインストール方法をご覧ください。

Gethがインストールできたことの確認

ターミナルを立ち上げて以下のコマンドを実行します。
バージョンも確認できます。

ヘルプ
$ geth --help

または

ヘルプ
$ geth --h

こんな感じでバージョンとかが表示されます。

NAME:
geth - the go-ethereum command line interface

Copyright 2013-2017 The go-ethereum Authors

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

VERSION:
1.7.3-stable

Gethの起動

これだけでも起動します。

起動
$ geth

ただし上記だとコンソールが出ず、ネットワークに接続してステータスとかを確認するだけのようです。

こうするとJavaScriptコンソールが出てコマンドが打てるようになります。

コンソール付きで起動
$ geth console

Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable/darwin-amd64/go1.9.2
coinbase: 0xa721495ea24ee2a4c14b8e57fec68f4acc3f1e57
at block: 0 (Thu, 01 Jan 1970 09:00:00 JST)
 datadir: /Users/tomo1026/Library/Ethereum
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> 

JavaScriptコンソールはManagement APIとJava Scriptを使ってインタラクティブにイーサリアムネットワークとやりとりができます。

色々画面上に出て来てうざい場合は以下のコマンドでログの表示を出力しないようにもできます。

コンソール付き、ログ出力無しで起動
geth console 2>> /dev/null

より詳しい説明は以下のページを参照。
https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console

イーサリアムネットワークでいくつかコマンドを試してみる

コンソールを立ち上げるとJava ScriptとManagement APIが打てるようになります。

いくつかコマンドを実行してみます。

ノード情報の取得
> admin.nodeInfo
{
  enode: "enode://7f21b360c4aca44729ffc4650d6e99d58b3ed4a72c69896c335422a5c6e7085bbb8b7701d2affbdcdaccd5a1c70d0fb05335a1228452413e993aaaa93ea9c0fc@192.168.100.19:30303",
  id: "7f21b360c4aca44729ffc4650d6e99d58b3ed4a72c69896c335422a5c6e7085bbb8b7701d2affbdcdaccd5a1c70d0fb05335a1228452413e993aaaa93ea9c0fc",
  ip: "192.168.100.19",
  listenAddr: "[::]:30303",
  name: "Geth/v1.7.3-stable/darwin-amd64/go1.9.2",
  ports: {
    discovery: 30303,
    listener: 30303
  },
  protocols: {
    eth: {
      difficulty: 17179869184,
      genesis: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
      head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
      network: 1
    }
  }
}

ブロック番号の取得
> eth.blockNumber
0
ブロック番号の取得
> eth.blockNumber
0
指定したブロック番号のブロック情報の取得
eth.getBlock(0)
{
  difficulty: 17179869184,
  extraData: "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
  gasLimit: 5000,
  gasUsed: 0,
  hash: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0x0000000000000000000000000000000000000000",
  mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  nonce: "0x0000000000000042",
  number: 0,
  parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 540,
  stateRoot: "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",
  timestamp: 0,
  totalDifficulty: 17179869184,
  transactions: [],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}
ネットワークに存在するノード数のカウント
> net.peerCount
3

ここで色々とethやらnetなどの接頭辞が付いています。
より詳しい説明は
https://github.com/ethereum/go-ethereum/wiki/Management-APIs

https://qiita.com/toshikase/items/fa7a826db483177d1e80
などを参照してください。

15
11
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
15
11