AWS Blockchain Template
簡単なメモ
AWSまったくわからんちんな人でも下記に従うとシュッとプライベートネットワークを建てられる
ECRに上がってるEthereumのノードのDockerImageをいじることができればもう少し柔軟に組めそう。
EthExplorer (よくあるトランザクションのエクスプローラ)
EthStats (ブロック数やらのダッシュボード)
https://gyazo.com/cd39b1f02a7a5a659a1ad6437d951aa8
見ての通りGas Priceは0に設定されています。
Ether Explorer
https://gyazo.com/ed3e504f9dfddf9fbc51613f42f77a9d
も同時に立てることができるので便利 ECSで立てるかDocker on EC2で省エネな感じで立てるかは選択可能
Docker-localの場合はt2.mediumだとExplorer使うにはスペック不足感ありました
(マイニングなどはちゃんとされる)
code:docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
123ec955d102 712425161857.dkr.ecr.us-west-2.amazonaws.com/eth-explorer:v1 "npm start" 12 minutes ago Up 12 minutes 0.0.0.0:8080->8080/tcp hardcore_shannon
63385e73abf9 712425161857.dkr.ecr.us-west-2.amazonaws.com/eth-netstats:v1 "npm start" 12 minutes ago Up 12 minutes 0.0.0.0:80->80/tcp gracious_pike
1c72c2f6621e 712425161857.dkr.ecr.us-west-2.amazonaws.com/client-go:v1 "/usr/bin/node /opt/…" 12 minutes ago Up 12 minutes unruffled_beaver
個人で立てるときは、非推奨ですが、IP割当がOnになっているPublic Subnetを割り当てるとPublicIPの振られた(HTTPでインターネット経由でアクセス可能な)
ノードが立ちます。IP割当がOnになっていないPublic Subnetを割り当てるとCloudFormationがコケます。
動いているgethコマンドを除く
code:geth
root 1 0.0 0.5 907280 45860 ? Ssl 00:52 0:01 /usr/bin/node /opt/geth-daemon/build/index.js --nodiscover --networkid 1234 --initial-difficulty 1 --log-level info --rpc --rpcapi web3,net,eth --rpcaddr 0.0.0.0 --rpcvhosts * --rpccorsdomain * --ws --wsapi web3,net,eth --wsaddr 0.0.0.0 --wsport 8546 --wsorigins bin boot cgroup dev etc home lib lib64 local lost+found media mnt opt proc root run sbin selinux srv sys tmp usr var --mine --minerthreads 1 --etherbase 0x0ADfCCa4B2a1132F82488546AcA086D7E24EA324 --funded-accounts 0x0ADfCCa4B2a1132F82488546AcA086D7E24EA324,0x0bd5EebDC3E53973dDF236D43906C776a5fE3784,0x9537cb86f5a03C8CCB52c44b49757861eCA0004b,0x1Fbc353788338F902630E5494aD7FaC7dF8dBb29,0x5ccBe3B9B15eFB62bB2696051091Ee7C1Eb4c7E6,0x0CDfCCa4B2a1132F82488546AcA086D7E24EA324,0x0dd5EebDC3E53973dDF236D43906C776a5fE3784,0x2537cb86f5a03C8CCB52c44b49757861eCA0004b,0x4Fbc353788338F902630E5494aD7FaC7dF8dBb29,0x9ccBe3B9B15eFB62bB2696051091Ee7C1Eb4c7E6 --targetgaslimit 8000000 --initial-block-gas-limit 8000000 --initial-account-balance 1000 --gasprice 0 --ethstats-ws-url ws://localhost:80 --ethstats-ws-secret xxxxxxxx
root 18 109 15.7 3054908 1288584 ? Sl 00:52 78:28 /opt/ethereum-go/bin/geth --nodiscover --networkid 1234 --rpc --rpcapi web3,net,eth --rpcaddr 0.0.0.0 --rpcvhosts * --rpccorsdomain * --ws --wsapi web3,net,eth --wsaddr 0.0.0.0 --wsport 8546 --wsorigins bin --mine --minerthreads 1 --etherbase 0x0ADfCCa4B2a1132F82488546AcA086D7E24EA324 --targetgaslimit 8000000 --gasprice 0
code:geth.version
bash-4.2# /opt/ethereum-go/bin/geth version
Geth
Version: 1.8.2-stable
Git Commit: b8b9f7f4476a30a0aaf6077daade6ae77f969960
Architecture: amd64
Network Id: 1
Go Version: go1.9.4
Operating System: linux
GOPATH=
GOROOT=/usr/local/go
geth attachして覗いてみる
code: geth attach
bash-4.2# /opt/ethereum-go/bin/geth attach
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.2-stable-b8b9f7f4/linux-amd64/go1.9.4
coinbase: 0x0adfcca4b2a1132f82488546aca086d7e24ea324
at block: 1461 (Mon, 01 Oct 2018 02:06:37 UTC)
datadir: /root/.ethereum
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
web3.personal.newAccount("hogehoge")
"0x7852300e5153ee414ed73bbba2bf7973b91593e3"
web3.personal.newAccount("hogehoge")
"0x03265d56fb80b1ad5e6c6c74993c65a7ec34f069"
web3.personal.newAccount("hogehoge")
"0x96e992e3a9dccac07be21bcc46cf7f18d962e737"
web3.eth.accounts
web3.eth.getBalance(web3.eth.coinbase)
8.515e+21
Truffle (Local) からつなぐ
code: truffle-config.js
module.exports = {
networks: {
development: {
host: "hogefuga.us-west-2.compute.amazonaws.com",
port: 8545,
network_id: "*",
}
}
};
code:truffle
truffle(development)> web3.eth.accounts
[ '0x7852300e5153ee414ed73bbba2bf7973b91593e3',
'0x03265d56fb80b1ad5e6c6c74993c65a7ec34f069',
'0x96e992e3a9dccac07be21bcc46cf7f18d962e737' ]
適当にハロワ書いてもこのままだとデプロイ出来ません
code:migrate
Running migration: 1_initial_migration.js
> Unlocking account 0x7852300e5153ee414ed73bbba2bf7973b91593e3
Deploying Migrations...
... undefined
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: authentication needed: password or unlock
Error: authentication needed: password or unlock デスヨネーunlockします
code: web3
web3.personal.unlockAccount(web3.eth.accounts0) とはいえこのアカウントETHを持っていないので雑にcoinbaseに設定してETHを付与する
code: setEtherbase
miner.setEtherbase(web3.eth.accounts0) miner.stop()
miner.start() // 反映
再度 migrate
code:migrate_result
% truffle migrate
Using network 'development'.
Running migration: 2_helloworld.js
Deploying HelloWorld...
... 0x13e71bdc13bcd9eec48cf000d6a21387484b8b80858b20e7066613b343992ebf
HelloWorld: 0xf780727dfe046cdceb5664db3ca31ec7eb3c0716
Saving successful migration to network...
... 0x02b309dddc58557832fba9f9e3cc2f5456636a42fccfdc5cbc38670e12aab29c
Saving artifacts..
code: 実行
truffle(development)> hw = HelloWorld.at(HelloWorld.address)
truffle(development)> hw.say()
'Private!' // 実行できてる
MetaMask経由でアクセスしてみる
MetaMask立ち上げ -> CustomRPC -> http://xxxxxxxx.us-west-2.compute.amazonaws.com:8545を入力
アカウント適当に作成して送金
code: 送金
eth.sendTransaction({from: eth.accounts0, to: toAddress, value: web3.toWei(10, "ether")}) https://gyazo.com/8f8507a1bb157dd72fadc82a43c9a1f2
NOTE