まず知っておくこと
Etherbaseとは
これは実際に自分がマイニングした時に報酬を受け取るためのアカウントのこと。
はじめの段階ではeth.accounts[0]と指定されているので、
確認するためにも下記のコマンドをターミナルで実行。
(geth,console起動)
$ cd ~/ethereum_data
$ geth --networkid 10 --nodiscover --maxpeers 0 --datadir ./ console console
Etherbaseで設定されているアカウントの確認をする
> eth.coinbase
"0x53c21065cce445d95dd0376083aca950f760d71d"
ここでもう一つアカウントを作成してみる。
> personal.newAccount('password')
"0xfd30920858f4cc882562183cc38cd71c45089088"
同一ノード上のアカウント数の確認をしてみると、
> eth.accounts
["0x53c21065cce445d95dd0376083aca950f760d71d", "0xfd30920858f4cc882562183cc38cd71c45089088"]
こうなっている。
2番目に作ったアカウント→[1]
> miner.setEtherbase(eth.accounts[1])
true
> eth.coinbase
"0xfd30920858f4cc882562183cc38cd71c45089088"
アカウント内に残高が入ってるかどうか確認してみる。
> eth.getBalance(eth.accounts[0])
0
> eth.getBalance(eth.accounts[1])
0
何もしていないので0。これはマイニングに成功した時やコントラクトの実行をしたときなどに増える。
> eth.blockNumber
0
consoleで実行
> miner.start(1)
マイニングを実行しているかどうか確かめたいときには
> eth.mining
true
その後、
> eth.getBalance(eth.accounts[1])
0
> eth.getBalance(eth.accounts[0])
240000000000000000000
> eth.blockNumber
48
↑単位はwei
Wei -> Etherへの変換
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
240
マイニング停止するには
> miner.stop()
となる。