RSK privatenetwork +Truffle + solidity
[versions]
EthereumJS TestRPC v4.0.1 (ganache-core: 1.0.1)
Truffle v3.4.3
gradle 4.2.1
RSKJ Ginger 0.2.5
web3 0.18.4 (https://github.com/ethereum/web3.js/)
目次ページ
https://github.com/rsksmart/rskj/wiki/Starting-with-RSK-Smart
(テストネットへ接続する方法
https://github.com/rsksmart/rskj/wiki/Install-RskJ-and-join-the-RSK-Ginger-Testnet )
スマートコントラクトをデプロイする:3つの方法がある
1: Truffleフレームワークを使う
手順A: https://github.com/rsksmart/rskj/wiki/Testing-RSK-Smart-Contracts-using-Truffle
解説:
サーバーレスフレームワークTruffleでÐappを爆速開発する ①Tutorial - Qiita
サンプルのスマートコントラクトと手順:
Create and deploy a Smart Contract (6/6) | ChainSkills
TruffleFramework.com | Building & Testing a Frontend App with Truffle 3.0
2: RSK Consoleを使う
3: RPCを使う
--メモ: その後使えるツール
Smart monitor app 説明
https://github.com/rsksmart/rskj/wiki/RSK-Smart-monitor-app
---------------------------------------
1: Truffleフレームワークを使ってスマートコントラクトをデプロイする用意
https://github.com/rsksmart/rskj/wiki/Testing-RSK-Smart-Contracts-using-Truffle
0: web3.jsをインストール
web3はtruffle consoleなどのEthereum関連で使うコマンドのライブラリです。
ページ: https://github.com/ethereum/web3.js/
API Reference: https://github.com/ethereum/wiki/wiki/JavaScript-API
1: testrpc, truffleコマンドが使えない
解決: nodeが使えなくなっていたのを直した
この解消方法→「dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.58.dylib」 - Qiita
2: testrpcを起動する
$ testrpc
起動しないままTruffleをセットアップ(truffle deploy, truffle migrateなど)をするとエラーが出る場合:
エラー: "Error: Invalid JSON RPC response: "" "
対策(有効な対策かどうかはわからない): geth console
> admin.startRPC("127.0.0.1", 8545, "*", "web3,db,net,eth")
3: truffle プロジェクトを作る
*この際のコマンドは webpackを使用する以下:
$ truffle init webpack
$ truffle compile
$ truffle migrate
$ npm run dev
localhost 8080にて動作確認: http://localhost:8080/
使った機能詳細: Truffle webpack https://github.com/trufflesuite/truffle-init-webpack
この機能を使わない場合のエラー(Truffle v3.4.3での場合):
$ truffle serve
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:124978 return (new fsevents(path)).on('fsevent', callback).start();
TypeError: fsevents is not a constructor
4:新たに作ったスマートコントラクトをcompile, migrate, deployする
エラー: truffle console > hello;
"Error: HelloWorld has not been deployed to detected network (network/artifact mismatch)"
(未解決) 同問題: Why are my contracts showing as not deployed in Truffle? - Ethereum Stack Exchange
=> ネットワークへコントラクトをデプロイできるtruffle projectで以下を実行
5:
(チュートリアルより)
truffle(development)> var hello = HelloWorld.deployed();
undefined
truffle(development)> hello;
結果が表示される。
そのコントラクトのアドレスを表示する方法:
hello.address これではできないので HelloWorld.address とする
2:RSKのノードを立ち上げる
主な手順: https://github.com/rsksmart/rskj/wiki/Compile-and-run-a-RSK-node-locally
ノードを立ち上げる方法A CLIを用いる方法、方法B IntelliJ IDEAを用いる方法の2つが紹介される。
注: のちのnode configをするために何れにしてもIntelliJ IDEAのインストールが必要。
公式チュートリアル: Compile and run a RSK node locally · rsksmart/rskj Wiki · GitHub
0: 事前に必要なのは RSKJのソースコード、JAVA 8 JDK。
1: ノード立ち上げの準備
ターミナルにてディレクトリを移動
/Users/UserName/rskj/gradle/wrapper へいく。
./gradlew build shadow -x test
*... "gradlew"ではなく "./gradlew"とする
このディレクトリがない場合:
エラー: Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
解決: gradleをインストールして gradle-wrapper.jarを作成
brew update
brew install gradle
ターミナルにてディレクトリを移動
/Users/UserName/rskj/gradle/wrapper へ移動する
gradle wrap
これによりこのディレクトリに新たに以下が追加される。
gradle , gradlew, gradlew.bat
(参考記事では「gradle/wrapper/gradle-wrapper.jarが作成される」と書いてある)
参考: gradlewが謎のエラーで動かない件について - Qiita
コマンドの結果 taskがないとエラーが出た場合:
Downloading https://services.gradle.org/di.....(省略)
FAILURE: Build failed with an exception.
* What went wrong: Task 'test' not found in root project 'wrapper'.
* Try: Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
解決:gradle buildというコマンドを rskj-coreディレクトリで行う
以下の2つのコマンドで同じエラーが出た
➜ rskj-core git:(master) ✗ gradle build
➜ rskj git:(master) ✗ gradle build
エラー: FAILURE: Build failed with an exception.
* Where: Build file '/Users/username/rskj/rskj-core/build.gradle' line: 172
* What went wrong: A problem occurred evaluating project ':rskj-core'.
> Could not find method dependencyVerification() for arguments [build_8gpq22py5h646olhiziop57xk$_run_closure10@3ab92c0] on project ':rskj-core' of type org.gradle.api.Project.
--
エラー: ➜ rskj-core git:(master) ✗ ../gradlew build
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
原因: gradle-wrapper.jarがないこと
解決: ➜ rskj git:(master) ✗ gradle wrap
+: gradle ファイルの中のwrapperファイルの中で同じコマンドを実行
3回目に成功して jarファイルができた
参考: gradlewが謎のエラーで動かない件について - Qiita
しかしまだbuildができない。
エラー: FAILURE: Build failed with an exception.
* Where: Build file '/Users/UserName/rskj/rskj-core/build.gradle' line: 27
* What went wrong: A problem occurred evaluating project ':rskj-core'.
> Plugin with id 'witness' not found.
解決: ./configure.shを実行
手順: https://github.com/rsksmart/rskj/wiki/Ensure-security-chain-of-RskJ-source-code
方法B:IntelliJ IDEAを用いる
buildのためにFinishというボタンを押しても赤い文字で以下の項目がハイライトされ、
エラーになっている場合:
パソコンの中にこれまで1つもJDKがない場合にエラーになるようです。
JAVA_HOME (not defined yet)
解決: アプリ開始画面から、JDKを新規作成
リンク: java - Intellij Idea: Importing Gradle project - getting JAVA_HOME not defined yet - Stack Overflow
エラー: plugin witnessがないというエラー
解決: gpgをインストール、gpgでソースコードを認証して、ターミナルで ./configure.shを実行
手順: https://github.com/rsksmart/rskj/wiki/Ensure-security-chain-of-RskJ-source-code
次に、gradleでプロジェクトをビルドする。
ターミナルより、rskjのディレクトリにて、
$ ./gradlew build shadow -x test
> Configure project :rskj-core
(省略)
BUILD SUCCESSFUL in 7s
11 actionable tasks: 2 executed, 9 up-to-date
と出たら、 これでGradleによるプロジェクトビルドが成功。
./rskj-core/build/libs/ のディレクトリに、"rskj-core-{version}-all.jar"というjarファイルができていることを確認する。
次に、configのセッティングをする。
("ノードの設定が足りない"というエラーでまだノードが立ち上がらないためだ。)
必要なNode情報:
- privateKey = <PRIVATE_KEY>
- coinbase.secret = <COINBASE_SECRET> (生成された"address"を入れる変数だと思われる)
- nodeId = <NODE_ID>
CLIを使う場合:
java -cp rskj-core-0.2.0-GINGER-all.jar co.rsk.GenNodeKeyId
https://ajlopez.wordpress.com/2017/06/11/running-an-ethereumrsk-node/
IntelliJ IDEAを使う場合:
Gradleでプロジェクトをインポートに成功させてから以下の手順。
手順: https://github.com/rsksmart/rskj/wiki/How-to-initialize-RSK-node-configuration-file-settings
手順が終わったら、rsk-sample.confへ以上の変数を定義する。
confファイルの設定を終えてから、
rskjディレクトリにて以下のコマンドを打つとノードが立ち上がる。
rskj $ java -Drsk.conf.file=[conf] -cp [jar] co.rsk.Start
[conf][jar]それぞれに、以下のようなパスを指定。
- [conf]: the path to the configuration file for the node. A sample configuration file can be found on:
/classes/production/rskj-core/config/rsk-sample.conf
. (.rskj-core/src/main/resources/config/rsk-sample.conf )
- [jar]: the path to the fatjar generated by the gradle shadow command. It can be found on
rskj-core/build/lib/rskj-core-{version}-all.jar
.
注: [conf]: rsk-sample.confファイルはチュートリアルの指定するパスにはなかったため、探した結果こちらにあった: .rskj-core/src/main/resources/config/rsk-sample.conf
例: $ java -Drsk.conf.file=.rskj-core/src/main/resources/config/rsk-sample.conf -cp ./rskj-core/build/libs/rskj-core-0.2.5-GINGER-all.jar co.rsk.Start
参考: https://github.com/rsksmart/rskj/wiki/Compile-and-run-a-RSK-node-locally
このコマンドでエラーが出た場合
エラー:
rskj git:(master) $ java -Drsk.conf.file=.rskj-core/src/main/resources/config/rsk-sample.conf -cp ./rskj-core/build/libs/rskj-core-0.2.5-GINGER-all.jar co.rsk.Start
2017-10-16-13:53:40.0310 INFO [start] Starting RSK
2017-10-16-13:53:40.0402 INFO [general] Config ( no ): default properties from resource 'rskj.conf'
2017-10-16-13:53:40.0405 INFO [general] Config ( no ): user properties from -Drskj.conf.res resource 'null'
2017-10-16-13:53:40.0405 INFO [general] Config ( no ): user properties from resource 'user.conf'
2017-10-16-13:53:40.0406 INFO [general] Config ( no ): user properties from file '/Users/HOkaniwa/rskj/config/rskj.conf'
2017-10-16-13:53:40.0406 INFO [general] Config ( no ): test properties from resource 'test-rskj.conf'
2017-10-16-13:53:40.0406 INFO [general] Config ( no ): test properties from resource 'test-user.conf'
2017-10-16-13:53:40.0407 INFO [general] Config ( no ): user properties from -Drsk.conf.file file '.rskj-core/src/main/resources/config/rsk-sample.conf'
2017-10-16-13:53:40.0444 ERROR [general] Can't read config.
解決: 指定したパスが長いため、何らかのスペルミスなどが原因だった。
新たなディレクトリを作って、コマンドを打つ
例:
➜ rskjdir ls
datadir logs rsk-sample.conf rskj-core-0.2.5-GINGER-all.jar
➜ rskjdir java -Drsk.conf.file=rsk-sample.conf -cp rskj-core-0.2.5-GINGER-all.jar co.rsk.Start
2017-10-17-21:00:59.0581 INFO [general] Config ( yes ): user properties from -Drsk.conf.file file 'rsk-sample.conf'などと出る
3: RSKとTruffleをつなぐ
これには
1: RSKノードを走らせておく (testrpcを走らせておく必要はない)
2: RSKノードのセットアップをまつ
(待たないとtruffle migrateで"Error: Contract transaction couldn't be found after 50 blocks"のエラーが出る)
3: TruffleのportをRSKのポートに設定する
truffle.jsの中のportを以下のように変えます。
// port: 8545,
port: 4444,
参考: https://github.com/rsksmart/rskj/wiki/Testing-RSK-Smart-Contracts-using-Truffle
4: Truffleを立ち上げる (truffle console, truffle serve / npm run build からの npm run dev)
参考: https://www.reddit.com/r/ethdev/comments/6iumql/how_can_i_configure_truffle_webpack_to_serve_on/
5: 動作確認 (例)
$ truffle console
truffle(development)> web3.eth.accounts
[ '0xf4fe95909b7agd30f9dfgt44535ce9e14e6f97aff5' ]
truffle(development)> web3.eth.blockNumber
3341
6: テストネットfaucetでRSKのコインを得る
??できていない (確認方法は web3.eth.toWeiのみ?)
エラー:
truffle(development)> web3.eth.toWei(web3.eth.getBalance(web3.eth.coinbase), 'ether');
TypeError: web3.eth.toWei is not a function
類似:
web3js - web3.eth.contract is not a function when making contract - Ethereum Stack Exchange
7: チェックツールを入れる
1: rpc-tests ->これじゃないかもしれない
- clone
$ git clone https://github.com/ethereum/rpc-tests
$ cd rpc-tests
$ git submodule update --init
$ npm install
https://github.com/ethereum/rpc-tests
2: マイナーが正常に動いているかを確認する sync3nodes.js => 見つからず
Go to utilities/rpc-test and type
npm install
then
node sync3nodes.js
参考:
https://github.com/rsksmart/rskj/wiki/Testing-RSK-Smart-Contracts-using-Truffle
3: マイニングされたブロックとマイナーをチェックするanalyzebc.js
last two numbers (400-450) are the range of blocks to be scanned.
node .\analyzebc.js localhost:4444 400-450
参考:
https://github.com/rsksmart/rskj/wiki/Testing-RSK-Smart-Contracts-using-Truffle
4: スマートコントラクトのデプロイ
5: マイニングできるノードの設定をする
手順: 新たなconfigファイルを作って、java .... co.rsk.Start コマンドで走らせる。
1: テストネットワークの中でマイナーを設定する場合:
https://github.com/rsksmart/rskj/wiki/Configure-your-RSK-node-for-mining
2: プライベートネットワークの中で、マイナーを設定する場合:
https://github.com/rsksmart/rskj/wiki/Compile-and-run-a-RSK-node-locally
用いるconfigファイル:
(minerでないサンプルノード 参考:
miner1~3:
https://raw.githubusercontent.com/wiki/rsksmart/rskj/configs/miner1.conf
https://raw.githubusercontent.com/wiki/rsksmart/rskj/configs/miner2.conf
https://raw.githubusercontent.com/wiki/rsksmart/rskj/configs/miner3.conf
?? 違い