geth: private netでのaccount作成、ノード起動、アカウント間送金
genesis fileを初期化
% geth --datadir ~/eth_private_net init ~/eth_private_net/myGenesis.json INFO [08-20|15:07:30.950] Maximum peer count ETH=25 LES=0 total=25 INFO [08-20|15:07:30.957] Allocated cache and file handles database=/Users/---/eth_private_net/geth/chaindata cache=16 handles=16 INFO [08-20|15:07:30.964] Writing custom genesis block INFO [08-20|15:07:30.965] Persisted trie from memory database nodes=0 size=0.00B time=389.117µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [08-20|15:07:30.965] Successfully wrote genesis state database=chaindata hash=7b2e8b…7e0432 INFO [08-20|15:07:30.965] Allocated cache and file handles database=/Users/----/eth_private_net/geth/lightchaindata cache=16 handles=16 INFO [08-20|15:07:30.968] Writing custom genesis block INFO [08-20|15:07:30.968] Persisted trie from memory database nodes=0 size=0.00B time=1.699µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [08-20|15:07:30.968] Successfully wrote genesis state database=lightchaindata hash=7b2e8b…7e0432
node起動コマンド
geth --networkid "1515" --nodiscover --datadir "~/eth_private_net" console 2>> ~/eth_private_net/geth_err.log Welcome to the Geth JavaScript console! instance: Geth/v1.8.13-stable/darwin-amd64/go1.10.3 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
アカウント作成とmining start/stop
> eth.accounts [] > personal.newAccount("<password>") "0x69f74bfd79fbd227362be370ffc457096275a7e2" > eth.account undefined > eth.accounts ["0x69f74bfd79fbd227362be370ffc457096275a7e2"] > personal.newAccount("password") "0xeaf421b7d87e68954ea194242e86ce1e99472c60" > eth.accounts ["0x69f74bfd79fbd227362be370ffc457096275a7e2", "0xeaf421b7d87e68954ea194242e86ce1e99472c60"] > eth.coinbase "0x69f74bfd79fbd227362be370ffc457096275a7e2" > miner.start() null > eth.blockNumber 0 > eth.blockNumber 18 > eth.mining true > miner.stop() true > eth.getBalance(eth.accounts[1]) 0 > eth.getBalance(eth.accounts[0]) 140000000000000000000 > web3.fromWei(eth.getBalance(eth.accounts[1]),"ether") 0 > web3.fromWei(eth.getBalance(eth.accounts[0]),"ether") 140 > eth.accounts ["0x69f74bfd79fbd227362be370ffc457096275a7e2", "0xeaf421b7d87e68954ea194242e86ce1e99472c60"]
accountアンロックとアカウント間送金
### account unlock #### 初期化 初回のみ 18000sアカウントを解除 personal.unlockAccount("account","<YOUR_PASSPHRASE>", 18000) ### account balance確認 > eth.getBalance(eth.accounts[0]) 140000000000000000000 > eth.getBalance(eth.accounts[1]) 0 #### account間での送金 > eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value:web3.toWei(5,"ether")}) "0x75de0968b0dc4a4598b45f0a7e454d6720ef6e10d928b6457d4ca35ac169ef05" //ここでminingされないとtxがblockに入ったのを自分のアカウントの変化に反映できないので、 > miner.start() null > eth.blockNumber 0 > eth.blockNumber 18 > eth.mining true // miningできているときはここが`true`。miningが止まってるときは`false` 。 確認するときは、`eth.mining`/`eth.hashrate`などで確認する。 > eth.getBalance(eth.accounts[0]) 195000000000000000000 //miningしたのでちょっと増えてる。 もともとbalanceが0だった`eth.accounts[1]`も > eth.getBalance(eth.accounts[1]) 5000000000000000000 //miningすることによって、きちんと送金処理が完了
miningしている様子(privatenet)
% tail -f geth_err.log INFO [08-20|15:08:12.112] Disk storage enabled for ethash caches dir=/Users/---/eth_private_net/geth/ethash count=3 INFO [08-20|15:08:12.112] Disk storage enabled for ethash DAGs dir=/Users/---/.ethash count=2 INFO [08-20|15:08:12.112] Initialising Ethereum protocol versions="[63 62]" network=1515 INFO [08-20|15:08:12.113] Loaded most recent local header number=0 hash=7b2e8b…7e0432 td=16384 INFO [08-20|15:08:12.113] Loaded most recent local full block number=0 hash=7b2e8b…7e0432 td=16384 INFO [08-20|15:08:12.113] Loaded most recent local fast block number=0 hash=7b2e8b…7e0432 td=16384 INFO [08-20|15:08:12.114] Regenerated local transaction journal transactions=0 accounts=0 INFO [08-20|15:08:12.116] Starting P2P networking INFO [08-20|15:08:12.117] RLPx listener up self="enode://42bf0b1200deb53b98338ee313a40b514ed2d134297a9657b9e7009247a2ba16d2ca956cd850c67bea9ac78bda66d7bdb6de075c1fbec486880835168c232d31@[::]:30303?discport=0" INFO [08-20|15:08:12.120] IPC endpoint opened url=/Users/---/eth_private_net/geth.ipc INFO [08-20|15:09:53.140] IPC endpoint closed endpoint=/Users/---/eth_private_net/geth.ipc INFO [08-20|15:09:53.141] Blockchain manager stopped INFO [08-20|15:09:53.141] Stopping Ethereum protocol INFO [08-20|15:09:53.141] Ethereum protocol stopped INFO [08-20|15:09:53.141] Transaction pool stopped INFO [08-20|15:09:53.142] Database closed database=/Users/---/eth_private_net/geth/chaindata INFO [08-20|15:09:55.063] Maximum peer count ETH=25 LES=0 total=25 INFO [08-20|15:09:55.070] Starting peer-to-peer node instance=Geth/v1.8.13-stable/darwin-amd64/go1.10.3 INFO [08-20|15:09:55.070] Allocated cache and file handles database=/Users/---/eth_private_net/geth/chaindata cache=768 handles=128 INFO [08-20|15:09:55.084] Initialised chain configuration config="{ChainID: 1515 Homestead: <nil> DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil> Byzantium: <nil> Constantinople: <nil> Engine: unknown}" INFO [08-20|15:09:55.084] Disk storage enabled for ethash caches dir=/Users/---/eth_private_net/geth/ethash count=3 INFO [08-20|15:09:55.084] Disk storage enabled for ethash DAGs dir=/Users/---/.ethash count=2 INFO [08-20|15:09:55.084] Initialising Ethereum protocol versions="[63 62]" network=1515 INFO [08-20|15:09:55.085] Loaded most recent local header number=0 hash=7b2e8b…7e0432 td=16384 INFO [08-20|15:09:55.085] Loaded most recent local full block number=0 hash=7b2e8b…7e0432 td=16384 INFO [08-20|15:09:55.085] Loaded most recent local fast block number=0 hash=7b2e8b…7e0432 td=16384 INFO [08-20|15:09:55.086] Loaded local transaction journal transactions=0 dropped=0 INFO [08-20|15:09:55.086] Regenerated local transaction journal transactions=0 accounts=0 INFO [08-20|15:09:55.087] Starting P2P networking INFO [08-20|15:09:55.088] RLPx listener up self="enode://42bf0b1200deb53b98338ee313a40b514ed2d134297a9657b9e7009247a2ba16d2ca956cd850c67bea9ac78bda66d7bdb6de075c1fbec486880835168c232d31@[::]:30303?discport=0" INFO [08-20|15:09:55.090] IPC endpoint opened url=/Users/---/eth_private_net/geth.ipc INFO [08-20|15:11:04.161] Etherbase automatically configured address=0x69F74BFD79fbD227362BE370Ffc457096275a7e2 INFO [08-20|15:11:08.930] Updated mining threads threads=0 INFO [08-20|15:11:08.930] Transaction pool price threshold updated price=18000000000 INFO [08-20|15:11:08.930] Starting mining operation INFO [08-20|15:11:08.932] Commit new mining work number=1 txs=0 uncles=0 elapsed=1.350ms INFO [08-20|15:11:14.158] Successfully sealed new block number=1 hash=44b46b…cbf3bf INFO [08-20|15:11:14.163] 🔨 mined potential block number=1 hash=44b46b…cbf3bf INFO [08-20|15:11:14.166] Commit new mining work number=2 txs=0 uncles=0 elapsed=2.434ms INFO [08-20|15:11:14.315] Successfully sealed new block number=2 hash=0ae50d…dc42a6 INFO [08-20|15:11:14.315] 🔨 mined potential block number=2 hash=0ae50d…dc42a6 INFO [08-20|15:11:14.316] Commit new mining work number=3 txs=0 uncles=0 elapsed=276.959µs INFO [08-20|15:11:14.561] Successfully sealed new block number=3 hash=25c5c1…a3edca INFO [08-20|15:11:14.562] 🔨 mined potential block number=3 hash=25c5c1…a3edca INFO [08-20|15:11:14.562] Mining too far in the future wait=2s INFO [08-20|15:11:16.565] Commit new mining work number=4 txs=0 uncles=0 elapsed=2.003s INFO [08-20|15:11:16.980] Successfully sealed new block number=4 hash=5ab0ed…43851a
node情報を管理
nodeのconfigデータを管理するのに参考にした。
- cf: .gitignore(vagrantfileと.gitignoreを管理するときにやるやり方)
/* !config !.gitignore !Vagrantfile .DS_store *~