ブロックチェーンをプライベートで試してみた
環境
- OS
- ubuntu17.10
- 試したブロックチェーンアプリ
- ethereum(1.7.3-stable-4bb3c89d)
- wallet
- simple-ether-wallet(node.js/meteor)
sa
- ブロックチェーンの保管場所
- /home/yosshi/eth_private_net/
プライベートネットでのセットアップ
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update -y
sudo apt-get install ethereum
cd /home/yosshi
mkdir eth_private_net
vi eth_private_net/myGenesis.json
---
{
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x400",
"alloc": {},
"coinbase": "0x3333333333333333333333333333333333333333",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x8000000",
"config": {}
}
---
geth --datadir /home/yosshi/eth_private_net/ init /home/yosshi/eth_private_net/myGenesis.json
...
< 略>
INFO [01-18|20:57:58] Successfully wrote genesis state database=lightchaindata hash=6231b0…a0300b
...
geth --networkid "10" --nodiscover --datadir "/home/yosshi/eth_private_net" console 2>> /home/yosshi/eth_private_net/geth_err.log
> eth.getBlock(0)
{
difficulty: 1024,
extraData: "0x",
gasLimit: 134217728,
< 略>
miner: "0x3333333333333333333333333333333333333333",
mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
nonce: "0x0000000000000042",
number: 0,
parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
< 略>
}
※コマンドは途中まで入力してtabキーで補完、候補表示ができます。
アカウント作成
> eth.accounts
[]
> personal.listAccounts
[]
> personal.newAccount("testpassword01")
"0x7f6823f9fb73e6caddcfcb2774fa33f922b885f1"
> personal.newAccount("testpassword02")
"0x02c3af22f67232bf689e4ff39dd2bd527da21d7f"
> eth.accounts
["0x7f6823f9fb73e6caddcfcb2774fa33f922b885f1", "0x02c3af22f67232bf689e4ff39dd2bd527da21d7f"]
> eth.coinbase
"0x7f6823f9fb73e6caddcfcb2774fa33f922b885f1"
※最初に作ったアカウントが採掘を行う際にその報酬を紐付けるEOA(Externally Owned Account)となっている(変更可)
ex.
> miner.etEtherbase(eth.accounts[1])
採掘
※coinの単位
通常はweiで表示される
- 1 ether $$=$$ 10^3 finney
- 1 ether $$=$$ 10^6 szabo
- 1 ether $$=$$ 10^18 wei
外部ツールからAPI的にアクセスさせる
geth --networkid "10" --nodiscover --datadir "/home/yosshi/eth_private_net" \
--mine --unlock 0x7f6823f9fb73e6caddcfcb2774fa33f922b885f1 \
--rpc --rpcaddr "127.0.0.1" --rpcport "8545" --rpccorsdomain "*" \
console 2>> /home/yosshi/eth_private_net/geth_err.log
---
Unlocking account 0x7f6823f9fb73e6caddcfcb2774fa33f922b885f1 | Attempt 1/3
Passphrase:
Welcome to the Geth JavaScript console!
<略>
- ※オプションの意味
- --nodiscover : ピアを自動接続させない
- --maxpeers 1 : 隣接接続数の最大を定義。左記例は1
- --network 10 : 1,2,3以外を設定する。プライベートネット識別用
サンプルウォレットアプリ
git clone https://github.com/a-mitani/simple-ether-wallet cd simple-ether-wallet npm install meteor
ブラウザで http://localhost:3000/ にアクセスする
他のノードとつなぐ
- 端末Aのアドレス : 192.168.1.108
- 端末Bのアドレス : 192.168.1.110
最初は接続ホストなし
> net.peerCount 0
接続先情報もなし
> admin.peers []
ノードの情報を表示する(端末A/B両方確認しておく)
> admin.nodeInfo.enode "enode://67d9469234048eb9e051ad1488dc686d47d31c9469acb6ee9c191e86e2fade22e38a19cb59b3b04ef0323fdd986e685ccc354429a1bb7b89adacd67cf02dec74@[::]:30303?discport=0"
※ @[::]:30303の部分が @IPアドレス:ポート番号。[::]はIPv6のlocalhostの意味。
端末Aで端末Bを登録
> admin.addPeer("ecnode://..BのnodeInfo...@192.168.1.110:30303?discport=0")
端末Bで端末Aを登録 (実際は端末AでBを登録したら両方ともnet.peerCountは1だしadmin.peersにも相手が登場したので以下実行していない)
> admin.addPeer("ecnode://..AのnodeInfo...@192.168.1.108:30303?discport=0")
参考
Installing Geth
Go implementation of the Ethereum protocol. Contribute to ethereum/go-ethereum development by creating an account on Git...
