合同会社kumanoteのTanakaです。
今回は、ethereum上のtokenを開発するにあたってのtipsを紹介したいと思います。
gethをdocker上で動かし、host上からrpcで接続できるようにしたので、その紹介になります。
Dockerfile
FROM ubuntu:16.04 # <- 容量重いので適時かえてください
MAINTAINER kumanote,LLC. # <- 適時かえてください
RUN mkdir -p /root/.ethereum
VOLUME ["/root/.ethereum"]
# install geth
RUN \
apt-get update -y && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:ethereum/ethereum && \
apt-get update -y && \
apt-get install -y ethereum solc
EXPOSE 8545
CMD ["/bin/sh"]
solcはgethを起動するだけなら不要です
genesis.json
{
"config": {
"chainId": 15, // ここはnetworkidに合わせておきます。
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x200", // ここが大きいと開発にならない(マイニングできなくなる)ので、このくらいがちょうどよかったです
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
ビルド
docker build -t kumanote/geth:v1.0.0 .
実行
init
docker run \
-v `pwd`/.ethereum:/root/.ethereum \
-p 8545:8545 \
kumanote/geth:v1.0.0 \ # <- 適時変えてください
geth --datadir /root/.ethereum --networkid 15 init /root/.ethereum/genesis.json
console立ち上げ
docker run \
-it \
-v `pwd`/.ethereum:/root/.ethereum \
-p 8545:8545 \
kumanote/geth:v1.0.0 \ # <- 適時変えてください
geth --datadir /root/.ethereum --networkid 15 --nodiscover --ipcpath /root/.ethereum/geth.ipc --rpc --rpcaddr "0.0.0.0" --rpcport "8545" --rpccorsdomain "*" console
確認
host OS上で curl
を rpcサーバーに投げ込むことで、動作を確認できます。
$curl -X POST http://localhost:8545/ --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1"}