LoginSignup
19
18

More than 5 years have passed since last update.

Ethereumのテストネット+Web3.jsで簡単なnode.jsとhtmlのサンプルが動いたのでメモ

Posted at

Ethereumのテストネット+Web3.jsでごにょごにょして、簡単なサンプルが動いたのでメモ。

Step1
ここを参考にgethを使ってContractを作成・実行するまでやってみた。
http://book.ethereum-jp.net/

Step2
ここを参考にnode環境にweb3.jsをインストールしてnode-app.jsを実行。
https://github.com/ethereum/wiki/wiki/JavaScript-API
node-app.jsはここです。もっと単純にコーディングもできることも確認。https://github.com/ethereum/web3.js/blob/master/example/node-app.js
nodeからはgethクライアントにアクセスするので--rpcオプション付きで起動しておく必要があります。これの説明がなくてハマったorz
これでnode.jsでブロックチェーンアプリが作れます。

Step3
ここのbalance.htmlを実行してみた。添付写真の通り。coinbaseの残高が表示されてます。
https://github.com/ethereum/web3.js/blob/master/example/balance.html
これもgethクライアントにアクセスするので--prcとさらに--rpccorsdomain="*"(クロスドメイン設定)を追加してgethを起動しておく。
これでhtmlを使ったブロックチェーンアプリが作れます。ただし、gethクライントに接続可能な状態にしておくので荒らされる可能性もあり、node.jsで作るのがよいかも?

スクリーンショット 2016-03-03 18.05.12.png

19
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18