ethereumで送金してみる

ethereumで送金してみる

ethereumをローカルで動かすことが出来るようになったので送金してみましょう。

インストール&初期設定あたりは以下を見てください
garapon.hatenablog.com



前回のデータを使ってテストネットを起動

$geth --networkid "10" --datadir "/home/gara/eth_data" --logfile "/home/gara/geth_01.log" --olympic console

また対話形式でやってみます。

> eth.getBalance(eth.accounts[0])
33000000000000000000                  //coinbaseは33ether持っている
> eth.getBalance(eth.accounts[1])
0                                     //2つ目のアカウントは0
>eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")}) //送金
Please unlock account 11b00fff3570ac74d66192ffc18d3621b0b3dc4e.
Passphrase:
could not unlock signer account
    at InvalidResponse (<anonymous>:-81262:-98)
    at send (<anonymous>:-159843:-98)
    at sendTransaction (<anonymous>:-133996:-98)
    at <anonymous>:1:1
> eth.accounts[0]
"0x11b00fff3570ac74d66192ffc18d3621b0b3dc4e"

送金依頼をするとパスワードを求められます。送金元のパスワードですね。間違えてみたら上記のようなエラーになりました。
こいつは「> personal.newAccount("GARAPON01")」というコマンドで作ったのでパスワードは「GARAPON01」です。
もっかいやってみる

>eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")}) 
Please unlock account 11b00fff3570ac74d66192ffc18d3621b0b3dc4e.
Passphrase:
Account is now unlocked for this session.
I1216 10:26:34.302442    1972 xeth.go:1055] Tx(0xf526695b562b1c77b8e6777ed7b1e8429d70e42e79a0698e8001b0aca38fb926) to: 0xcf573ec35da6c35ded1a5416461de11bec0c89c0
"0xf526695b562b1c77b8e6777ed7b1e8429d70e42e79a0698e8001b0aca38fb926"
> eth.getBalance(eth.accounts[0])
33000000000000000000
> eth.getBalance(eth.accounts[1])
0

出来たー。送金依頼するとトランザクションIDが返却されますね。
そしてまだブロックに書き込んでいないので残高は減っていません。このあたりは当たり前ですがBitcoinと同じです。

さて採掘しましょう

> miner.start()
I1216 10:41:24.681754    1972 miner.go:119] Starting mining operation (CPU=1 TOT=2)
I1216 10:41:24.684756    1972 worker.go:570] commit new work on block 23 with 1 txs & 0 uncles. Took 2.678658ms
true
> I1216 10:41:24.687709    1972 ethash.go:220] Generating DAG for epoch 0 (size 1073739904) (0000000000000000000000000000000000000000000000000000000000000000)
I1216 10:41:24.686780    1972 backend.go:331] Automatic pregeneration of ethash DAG ON (ethash dir: /home/gara/.ethash)
I1216 10:41:24.690974    1972 backend.go:338] checking DAG (ethash dir: /home/gara/.ethash)
> !lsI1216 10:41:25.968282    1972 ethash.go:237] Done generating DAG for epoch 0, it took 1.280579052s
> eth.blockNumber
22
> eth.blockNumber
22
> miner.hashrate //採掘できているか良くわからない時はハッシュレートを見ましょう。
12912            //0以上なら採掘しているということになります。
> eth.blockNumber
27
> miner.stop()
true
> eth.blockNumber
31
>

ほれました。しかしgethを起動する時にログをリダイレクトしておかないと見難いですね。
ほれたので見てみると。。。

> eth.getBalance(eth.accounts[0])    
36500000000000000000
> eth.getBalance(eth.accounts[1])
10000000000000000000
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
36.5
> web3.fromWei(eth.getBalance(eth.accounts[1]),"ether")
10

送金は出来ていますがCoinBaseから送ったので報酬が入ってしまってわかりにくくなってますね。
36.5=33 - 10 + 13.5(9ブロック掘った報酬 1.5*9)
手数料が計算されていないのは手数料は採掘者=アカウント0に振り込まれるのでキャッシュバックされて手数料無料ということですね。
なので正しくは
36.5=33 - 10 + 16.5(9ブロック掘った報酬) - XXXX(送金にかかる手数料) + XXXX(採掘者に振り込まれる手数料)
となっています。

CoinBaseではないアカウントで検証するようにしないと駄目だな。
ということでもう一人作ってやってみます。

>  personal.newAccount("GARAPON03")
"0x851cc0735985613418397b6a409e456393d2653e"
> eth.getBalance(eth.accounts[2])
0
> {{from: eth.accounts[1], to: eth.accounts[2], value: web3.toWei(3, "ether")})
Please unlock account cf573ec35da6c35ded1a5416461de11bec0c89c0.
Passphrase:
Account is now unlocked for this session.
I1216 12:44:32.270342    1972 xeth.go:1055] Tx(0x6e9a0b40f1e21056b37b310d8ad9e39e2cebe6bb82693bd23ade757babd60181) to: 0x851cc0735985613418397b6a409e456393d2653e
"0x6e9a0b40f1e21056b37b310d8ad9e39e2cebe6bb82693bd23ade757babd60181"
> miner.start()
true
> eth.blockNumber
33
> eth.blockNumber
34
> miner.stop()
true
> eth.blockNumber
34
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
41.00105
> web3.fromWei(eth.getBalance(eth.accounts[1]),"ether")
6.99895
> web3.fromWei(eth.getBalance(eth.accounts[2]),"ether")
3

出来ましたね。
・アカウント01:36.5 + 4.5(3ブロック採掘報酬 1.5*3)+0.00105(手数料収入)
・アカウント02:10-3(送金額)-0.00105(手数料)
・アカウント03:3(受信額)


それにしてもethereumはコマンドが豊富なのでわかりやすい。
eth や miner と打ってTabを2回押すとその後の候補を表示してくれるので非常に使いやすいですね。

> miner.  //この状態でTab2回
miner.hashrate     miner.setExtra     miner.start
miner.makeDAG      miner.setGasPrice  miner.stopAutoDAG
miner.setEtherbase miner.startAutoDAG miner.stop
> miner.

ブロックチェーンより非常に勉強しやすい印象です。