プログラム上達したいな blog

プログラム書けるようになりたいアウトプット用

ethereum プライベートネットワークをdockerで動かしてみた

参考

enomotodev.hatenablog.com

 

これほんとわかりやすい

 

実行結果だけ載せときます

 

 

docker run -it --name geth golang:1.9 /bin/bash

f:id:gjjjjcdssvgg:20181023042512p:plain

 

 

git clone -b release/1.8 https://github.com/ethereum/go-ethereum ~/go-ethereum

f:id:gjjjjcdssvgg:20181023042515p:plain

 

 

cd ~/go-ethereum/

f:id:gjjjjcdssvgg:20181023042535p:plain

 

 

make geth

f:id:gjjjjcdssvgg:20181023042541p:plain

*以下省略

f:id:gjjjjcdssvgg:20181023042627p:plain

 

 

 

export PATH=/root/go-ethereum/build/bin:$PATH

f:id:gjjjjcdssvgg:20181023042539p:plain

 

 

 

geth version

f:id:gjjjjcdssvgg:20181023043952p:plain

 

 

mkdir ~/geth
cat << EOS > ~/geth/genesis.json

f:id:gjjjjcdssvgg:20181023044115p:plain

 

 

 

geth --datadir ~/geth/ init ~/geth/genesis.json

f:id:gjjjjcdssvgg:20181023042658p:plain

 

 

 

geth --networkid 10 --datadir ~/geth/ console 2>> ~/geth/error.log

f:id:gjjjjcdssvgg:20181023044457p:plain

 

 

 

eth.getBlock(0)

f:id:gjjjjcdssvgg:20181023045011p:plain

 

 

 

eth.getBlock(1)

f:id:gjjjjcdssvgg:20181023042616p:plain

 

 

 

personal.newAccount("password")

f:id:gjjjjcdssvgg:20181023042620p:plain

 

 

 

 

eth.accounts[0]

f:id:gjjjjcdssvgg:20181023042643p:plain

 

 

 

eth.coinbase

f:id:gjjjjcdssvgg:20181023042650p:plain

 

 

 

 

miner.start(1)

f:id:gjjjjcdssvgg:20181023042702p:plain

 

 

 

eth.mining

f:id:gjjjjcdssvgg:20181023042711p:plain

 

 

 

 

miner.stop()

f:id:gjjjjcdssvgg:20181023042719p:plain

 

 

 

 

eth.getBalance(eth.accounts[0])

f:id:gjjjjcdssvgg:20181023042622p:plain

 

マイニングは少し待たないと結果が反映されない

 

f:id:gjjjjcdssvgg:20181023045612p:plain

 

 

 

 

web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")

f:id:gjjjjcdssvgg:20181023042652p:plain

 

 

 

personal.lockAccount(eth.accounts[0])

f:id:gjjjjcdssvgg:20181023042726p:plain

 

 

 

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

f:id:gjjjjcdssvgg:20181023042717p:plain

 

eth.account[0]からeth.account[1]に10ether送金している

 

 

 

 

eth.getTransaction("0xdd4f3f940c6cc4fb6382eeec9f04cd864547bsybyceajvuci736r9z03c6")

f:id:gjjjjcdssvgg:20181023042611p:plain

 

 

blockNumberが「null」

なのでこのトランザクション

ブロックに取り込まれていない

ということで

 

また、マイニングを再開して

ブロックにトランザクション

取り込んでいく

 

 

f:id:gjjjjcdssvgg:20181023042625p:plain

 

 

blockNumberが「35」になったので

トランザクションがブロックに

取り込まれた

 

 

 

 

web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")

f:id:gjjjjcdssvgg:20181023042639p:plain

 

実際にeth.account[0]からeth.account[1]に

10ether送金されたことが確認出来た

 

 

 

 

 

おわりに

 

f:id:gjjjjcdssvgg:20181023042655p:plain

 

1ブロック毎に5ether報酬をもらってるっぽい