geth インストールと設定(1/2)┃スマートコントラクト開発環境構築
Ethereum上で実行可能なスマートコントラクト開発の環境構築を行います。
目次
gethのインストール
gethはスマートコントラクトの生成や実行、送金、アカウント生成、マイニング等。
Ethereumで必要なことはほとんど行う事が出来ます。
インストール先を作成
今後管理しやすいように
C:\mkdir ethereum
Cドライブ直下にethereumフォルダを作成しました。
ダウンロード
環境によりますが、2018/01/16時点 Windows Geth1.7.3 64-bit 34.69MB をダウンロードしました。
geth-windows-amd64-1.7.3-4bb3c89d.exe
実行します。
I Agree をクリック
Geth にチェックが入っていることを確認して Next をクリック
インストール先を C:\ethereum\Geth にして Install をクリック
インストールが完了したらgeth.exeがインストール先のフォルダにある事を確認します。
プライベートネットワークで起動
genesis.jsonを作成
{ "config": { "chainId": 10, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "alloc": {}, "coinbase" : "0x0000000000000000000000000000000000000000", "difficulty" : "0x00", "extraData" : "0x00", "gasLimit" : "0x2fefd8", "nonce" : "0x0000000000000042", "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp" : "0x00" }
privateフォルダを作成し保存。
C:\ethereum\Geth\private\genesis.json
初期化処理の実行
C:\ethereum\Geth>geth --datadir C:\ethereum\Geth\private init C:\ethereum\Geth\private\genesis.json
実行結果
WARN [01-16|14:48:20] No etherbase set and no accounts found as default INFO [01-16|14:48:21] Allocated cache and file handles database=C:\\ethereum\\Geth\\private\\geth\\chaindata cache=16 handles=16 INFO [01-16|14:48:21] Writing custom genesis block INFO [01-16|14:48:21] Successfully wrote genesis state database=chaindata hash=a98d19…1a4cb3 INFO [01-16|14:48:21] Allocated cache and file handles database=C:\\ethereum\\Geth\\private\\geth\\lightchaindata cache=16 handles=16 INFO [01-16|14:48:21] Writing custom genesis block INFO [01-16|14:48:21] Successfully wrote genesis state database=lightchaindata hash=a98d19…1a4cb3
No etherbase set and no accounts found as default
デフォルトとしてアカウントが無いという警告のようです。アカウントの作成を行う前なので無視します。
gethを起動
C:\ethereum\Geth>geth --networkid "10" --nodiscover --datadir "C:\ethereum\Geth\private" --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --rpcapi "eth,net,web3,personal" --targetgaslimit "20000000" console 2>> C:\ethereum\Geth\private\geth_err.log
成功時は
Welcome to the Geth JavaScript console! instance: Geth/v1.7.3-stable-4bb3c89d/windows-amd64/go1.9 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 >
上記のように表示されコンソールが起動します。
アカウントの作成
必要なだけ作成します。今回は4アカウント作成。 4アカウント共にパスワードは"password"としています。
> personal.newAccount("password") "0x6ba8d1e97893ca96bd53178402f4c2d50f1ccdc7" > personal.newAccount("password") "0x735655b691570d27cd9a28374662374d9603f769" > personal.newAccount("password") "0xc52eed5f3c1a1a0394238719e1a4d3451612ee1c" > personal.newAccount("password") "0x1b3f50b8a73d5ab0d7b1eedf1e20a1e3200cb816"
アカウントの確認
> eth.accounts ["0x6ba8d1e97893ca96bd53178402f4c2d50f1ccdc7", "0x735655b691570d27cd9a28374662374d9603f769", "0xc52eed5f3c1a1a0394238719e1a4d3451612ee1c", "0x1b3f50b8a73d5ab0d7b1eedf1e20a1e3200cb816"]
マイニングを行うcoinbaseアカウントの確認
> eth.coinbase "0x6ba8d1e97893ca96bd53178402f4c2d50f1ccdc7"
genesisブロックの確認
> eth.getBlock(0) { difficulty: 0, extraData: "0x00", gasLimit: 3141592, gasUsed: 0, hash: "0xa98d196b30b64f8ebc90f4b4e98ad9d77a016967db9c5de023a544b2981a4cb3", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0x0000000000000000000000000000000000000000", mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000", nonce: "0x0000000000000042", number: 0, parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000", receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", size: 504, stateRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", timestamp: 0, totalDifficulty: 0, transactions: [], transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", uncles: [] }
上記をもって geth マイニングと送金(2/2)┃スマートコントラクト開発環境構築 へ続く

この記事へのコメントはこちら