Ethereum マイニングと送金

マイニング(採掘)する

gethを起動しアカウントの作成と確認。

geth --networkid "10" --datadir "D:\Ethereum\etherdata10" --olympic console 2>D:\Ethereum\log\eth.log

accountを作成(既に2つ作成済みの状態)

> eth.accounts[0]
"0xe76dac08981340ff9343ca791bc4b8267603889f"
# meの変数に格納しておく
> me = eth.accounts[0]
"0xe76dac08981340ff9343ca791bc4b8267603889f"

# 3つ目のアカウントを作成
> personal.newAccount("password")
"0x29d2fc7cdcb294d0cb78a722b8fb5d30aa641393"

マイニングしてetherを稼いでおく

> miner.start(4)
# しばらく待って
> miner.stop()
# 手持ちのetherを確認する
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
> 251.87

送金する

参考:https://ethereum.gitbooks.io/frontier-guide/content/ether_transfer.htmlhttp://book.ethereum-jp.net/content/first_use/sending_ether.html

アカウントを確認する

# 参考までにmeはcoinBaseと同値
> me
"0xe76dac08981340ff9343ca791bc4b8267603889f"
> eth.coinbase
"0xe76dac08981340ff9343ca791bc4b8267603889f"

> eth.accounts
["0xe76dac08981340ff9343ca791bc4b8267603889f", "0x0c987d5001bebaabe0602cbea2304c4ab7b67874", "0x29d2fc7cdcb294d0cb78a722b8fb5d30aa641393"]

3つ目のアカウントに送金する

# 3つ目のアカウントの残高
> web3.fromWei(eth.getBalance(eth.accounts[2]), "ether")
0

# 送金先の変数を設定
> receiver = eth.accounts[2];
"0x29d2fc7cdcb294d0cb78a722b8fb5d30aa641393"

# 金額の変数を設定/金額は0.3ether
> amount = web3.toWei(0.30, "ether")
"300000000000000000"

# 送金
> eth.sendTransaction({from:me, to:receiver, value: amount})
Please unlock account e76dac08981340ff9343ca791bc4b8267603889f.
Passphrase:
Account is now unlocked for this session.
"0x822981399c79fc0eb8900efe5c976546f722e89b00294df1781e0c223a6736de"

# 3つ目のアカウント残高を見る。まだblockに書き込まれていない状況
> web3.fromWei(eth.getBalance(eth.accounts[2]), "ether")
0

# マイニングする
> miner.start(3)
true
> miner.stop()
true

# 3つ目のアカウント残高を見る/0.3ether送金された
> web3.fromWei(eth.getBalance(eth.accounts[2]), "ether")
0.3

# トランザクションを確認する
> eth.getTransaction("0x822981399c79fc0eb8900efe5c976546f722e89b00294df1781e0c223a6736de")
{
  blockHash: "0x5aceeeb030bde71fa0e4dac0f72545d123fcf54b2ed8bee6f26a9e9ec000020b",
  blockNumber: 169,
  from: "0xe76dac08981340ff9343ca791bc4b8267603889f",
  gas: 90000,
  gasPrice: 50000000000,
  hash: "0x822981399c79fc0eb8900efe5c976546f722e89b00294df1781e0c223a6736de",
  input: "0x",
  nonce: 3,
  to: "0x29d2fc7cdcb294d0cb78a722b8fb5d30aa641393",
  transactionIndex: 0,
  value: 300000000000000000
}