Ethereumクライアント「Geth」をMacOSに設定してみた

目次

Geth環境をインストールする

$ brew tap ethereum/ethereum
$ brew install ethereum

とやったところ、/usr/local以下に書き込めないとのエラー(Operation not Permitted)が出た。

sudoつけてやっても同様。。。

で、調べてみたら、セキュリティ機能(SIP:System Integrity Protection)「Rootless」が原因とのこと。

こちらを参考にしてSIPをdisenabelにしたところ、無事インストールできた。

Geth環境で操作する

ジェネシスブロックの生成準備

$ mkdir /Users/hoge/eth_private

$ cd /Users/hoge/eth_private

genesis.jsonをエディタで作成する

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

ジェネシスブロックを生成する

$ geth –datadir /Users/hoge/eth_private/ init /Users/hoge/eth_private/genesis.json

WARN [01-07|14:03:17] No etherbase set and no accounts found as default
INFO [01-07|14:03:17] Allocated cache and file handles database=/Users/hoge/eth_private/geth/chaindata cache=16 handles=16
INFO [01-07|14:03:17] Writing custom genesis block
INFO [01-07|14:03:17] Successfully wrote genesis state database=chaindata hash=6231b0…a0300b
INFO [01-07|14:03:17] Allocated cache and file handles database=/Users/hoge/eth_private/geth/lightchaindata cache=16 handles=16
INFO [01-07|14:03:17] Writing custom genesis block
INFO [01-07|14:03:17] Successfully wrote genesis state database=lightchaindata hash=6231b0…a0300b

コンソールに入る

$ geth –networkid “10” –nodiscover –datadir “/Users/hoge/eth_private” console 2>> /Users/hoge/eth_private/geth_err.log

Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable/darwin-amd64/go1.9.2
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

ブロック情報を表示する

> eth.getBlock(0)
{
difficulty: 1024,
extraData: “0x”,
gasLimit: 134217728,
gasUsed: 0,
hash: “0x6231b02ac967dff9b0c799e956094408959de862d720d08776302ffefba0300b”,
logsBloom: “0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000”,
miner: “0x3333333333333333333333333333333333333333”,
mixHash: “0x0000000000000000000000000000000000000000000000000000000000000000”,
nonce: “0x0000000000000042”,
number: 0,
parentHash: “0x0000000000000000000000000000000000000000000000000000000000000000”,
receiptsRoot: “0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421”,
sha3Uncles: “0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347”,
size: 507,
stateRoot: “0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421”,
timestamp: 0,
totalDifficulty: 1024,
transactions: [],
transactionsRoot: “0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421”,
uncles: []
}

アカウントの確認

> eth.accounts
[] ←なんもなし

アカウントの作成

personal.newAccount(“password”)で作成する
> personal.newAccount(“hoge01”)
“0x767442ad5473b80e17ce323fc0f7f43fd015c9ba”
> personal.newAccount(“hoge02”)
“0x074d1d753bb71e3adf357c8cc4dd5f8c9f94542f”
> eth.accounts
[“0x767442ad5473b80e17ce323fc0f7f43fd015c9ba”, “0x074d1d753bb71e3adf357c8cc4dd5f8c9f94542f”]

残高確認とマイニング

マイニングに利用するアドレスの確認

> eth.coinbase
“0x767442ad5473b80e17ce323fc0f7f43fd015c9ba”

アドレスの残高の確認

> eth.getBalance(eth.accounts[0])
0

マイニングの開始

> miner.start()
null

ハッシュレートを確認する(0でなければ、マイニングが進んでいる)
少し時間かかるみたいですね。。。
> miner.getHashrate()
34736

マイニングの停止

> miner.stop()
true

残高確認

> eth.getBalance(eth.accounts[0])
225000000000000000000
> eth.getBalance(eth.accounts[1])
0
数値はwei(10^18)で表示されています。
ethの単位で表示するにはこんな感じで。。
> web3.fromWei( eth.getBalance(eth.accounts[0]), “ether”)
225

マイニングしたEthreumeを送金する

送金する

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1, “ether”)})

※アドレスを書いてもいい
> eth.sendTransaction({from: “0x767442ad5473b80e17ce323fc0f7f43fd015c9ba”, to: “0x074d1d753bb71e3adf357c8cc4dd5f8c9f94542f”, value: web3.toWei(1, “ether”)})

Error: authentication needed: password or unlock ← 口座をunlockしてないのでエラーとなる
at web3.js:3143:20
at web3.js:6347:15
at web3.js:5081:36
at <anonymous>:1:1

送金元をunlockします

> personal.unlockAccount(eth.accounts[0], “hoge01”)
true
> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1, “ether”)})
“0x367d154ca64cbcd32c787f9806cce2978615c12a192a7548b442de81ff59aecc”

ペンディングトランザクションを確認する

> eth.pendingTransactions
[{
blockHash: null,
blockNumber: null,
from: “0x767442ad5473b80e17ce323fc0f7f43fd015c9ba”,
gas: 90000, ← トランザクション処理時のgasの最大値
gasPrice: 18000000000, ← トランザクション処理時に支払う1gasあたりの手数料(wei)
hash: “0x367d154ca64cbcd32c787f9806cce2978615c12a192a7548b442de81ff59aecc”,
input: “0x”,
nonce: 0,
r: “0xf4df16bbefccaaf34f905cedf1ca6f1800745a8c090b5092c1ad56902ec7cf21”,
s: “0x77f56abc1847e2c79b569ecf5e2d83322c5ee24a7e8046ef443751989f8f3696”,
to: “0x074d1d753bb71e3adf357c8cc4dd5f8c9f94542f”,
transactionIndex: 0,
v: “0x1c”,
value: 1000000000000000000
}]

送金確認

> miner.start() ← マイニング開始
null
> eth.hashrate ← ハッシュレート確認
> miner.stop() ← マイニング停止
true
> eth.pendingTransactions ← ペンディングトランザクションがなくなっている
[]
> eth.getBalance(eth.accounts[1]) ← 送金されている
1000000000000000000

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です