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
?? 違い
geth 1.6.7 と Solidity 0.4.18 でスマートコントラクトを走らせる方法リスト
バージョン
geth: 1.6.7
solc: 0.4.18-develop.2017.10.12+commit.81f9f86c.Darwin.appleclang
状況:
Solidityのスマートコントラクトをコンパイル後、
gethクライアントでEthereumへスマートコントラクトを送ることができなかった。
使えたチュートリアル:
from 多くのコメントが充実しているページ:
abi入力、parseのコマンドがエラーになって使えなかったチュートリアル:
https://qiita.com/toshikase/items/28725215f7ad678b4b68
https://ethereum.stackexchange.com/questions/15435/how-to-compile-solidity-contracts-with-geth-v1-6
gethでのSolidityセットアップ
全ての場合についてのチュートリアル:
http://solidity.readthedocs.io/en/develop/installing-solidity.html
[解決]ソースからbuildする場合:
http://block-chain.jp/tech/install-solidity-solc-on-mac/
インストールされていることを確認する方法:
$ which solc
パスが出てきたらインストールされている。
gethターミナルでのeth.getCompiler()メソッドはもう使われていないのでこちらを用いる。
homebrewでインストールする場合:
公式チュートリアル: Contract Tutorial · ethereum/go-ethereum Wiki · GitHub
[未解決] こちらのコマンドでの一連のエラーを紹介: brew install solidity
1: 2つのエラー
エラー:
・Z3 SMT solver NOT found. CMake Error: The following variables are used in this project, but they are set to NOTFOUND
・GitHub (GitHub::AuthenticationFailedError)
The GitHub credentials in the macOS keychain may be invalid.
エラー詳細:
==> cmake . -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG==> cmake . -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUGLast 15 lines from /Users/name/Library/Logs/Homebrew/solidity/01.cmake:-- TARGET_PLATFORM Target platform Darwin
---------------------------------------------------------------
(省略)
Z3 SMT solver NOT found.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:/tmp/solidity-20171012-2023-5alie/solidity_0.4.17/libdevcore/Boost_INCLUDE_DIR
used as include directory in directory /tmp/solidity-20171012-2023-5alie/solidity_0.4.17/libdevcore
-- Configuring incomplete, errors occurred!
See also "/tmp/solidity-20171012-2023-5alie/solidity_0.4.17/CMakeFiles/CMakeOutput.log".
If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
https://github.com/ethereum/homebrew-ethereum/issues
/usr/local/Homebrew/Library/Homebrew/utils/github.rb:210:in `raise_api_error': GitHub (GitHub::AuthenticationFailedError)
The GitHub credentials in the macOS keychain may be invalid.
Clear them with:
printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase
Or create a personal access token:
https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrew
and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"
解決: Github keychainを作成してexport pathを設定
brew search して GitHub API rate limit で怒られたときの対処方法 - Qiita
ー
2: 2つのエラー
Z3 SMT solver NOT found.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
/tmp/solidity-20171012-7826-1o690xi/solidity_0.4.17/libdevcore/Boost_INCLUDE_DIR
used as include directory in directory /tmp/solidity-20171012-7826-1o690xi/solidity_0.4.17/libdevcore
-- Configuring incomplete, errors occurred!
See also "/tmp/solidity-20171012-7826-1o690xi/solidity_0.4.17/CMakeFiles/CMakeOutput.log".
If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
https://github.com/ethereum/homebrew-ethereum/issues
These open issues may also help:
Add a dependency on jsoncpp for solidity? https://github.com/ethereum/homebrew-ethereum/issues/123
Error when installing Solidity compiler https://github.com/ethereum/homebrew-ethereum/issues/96
XcodeDefault.xctoolchain/usr/bin/ranlib: file: libsolidity.a(AsmAnalysisInfo.cpp.o) has no symbols https://github.com/ethereum/homebrew-ethereum/issues/128
Add ccache dependency and adds a bottle https://github.com/ethereum/homebrew-ethereum/pull/119
解決策が見つからなかったのでソースからビルドしました。
Parityセットアップ
参考:
https://github.com/paritytech/parity
Install from bashができなかった:
➜ ~ bash <(curl -kL -s -k -v --tlsv1.2 https://get.parity.io)
* Rebuilt URL to: https://get.parity.io/
* Trying 2400:cb00:2048:1::681b:840a...
* TCP_NODELAY set
* Connected to get.parity.io (2400:cb00:2048:1::681b:840a) port 443 (#0)
* SSL peer handshake failed, the server most likely requires a client certificate to connect
* Curl_http_done: called premature == 1
* Closing connection 0
Build from Sourceを実行:
➜ ~ curl https://sh.rustup.rs -sSf | sh
➜ ~ git clone https://github.com/paritytech/parity
➜ ~ cd parity
➜ parity git:(master) cargo build --release
------------------------------
これだけだと parityというコマンドがターミナルで使えない。
よって以下:
➜ target git:(master) cp -f /Users/username/parity/target/release/parity /usr/local/bin
ネットワークへ接続
普通:
parity — chain=ropsten
高速にする方法:
Is it possible to make the Parity software sync faster? - Ethereum Stack Exchange
➜$ parity --warp --mode active --tracing off --pruning fast --db-compaction ssd --cache-size 1024
この状態でウェブブラウザでこちらへアクセスすると
Parityのユーザインタフェースが現れる: http://127.0.0.1:8180
------------------------------
インターフェースの使い方:
Setting up Ethereum smart contract development using Parity on Ubuntu
公式 smart contractを走らせるチュートリアル:
Smart Contracts · paritytech/parity Wiki · GitHub
パソコンの時間がずれているというポップアップ画面が出て来た場合:
1: sudo ntpdate -u time.asia.apple.com
2:Parityを再起動
参考: Mac のターミナル上で OS の時刻情報を確認・変更する方法 | gotohayato
------------------------------
このままだとお金がないので、送金もスマートコントラクトのデプロイもできない。
初期金額を得るためには、少なくとも以下の3つの方法がある。
1: (Ropsenネットワークの)Etherを送ってくれるサービスに、自分のアドレスを登録してリクエストする
http://faucet.ropsten.be:3001/
2: genesis blockで設定する (プライベートネットワークを構築する場合のみ)
3: Ropsenネットワーク( またはプライベートネットワーク)でマイニングする
久々のRailsメモ: devise、scaffold、scaffoldによるviewエラー
ユーザー認証: deviseを用いてメールによる認証を行う
他:
ログイン認証も簡単!Railsでのdeviseの使い方 | TechAcademyマガジン
Scaffold
Scaffoldによるviewでのエラー対応:
Library not loaded: libmysqlclient.18.dylib (LoadError) の対処
環境
mysql 5.7
homebrew 1.3.2
まとめ記事:
未解決だった問題:
新たに入れた、ダウングレードしたバージョンのmysqlは確かにlibmysqlclient.18.dylibをパソコンに入れていたが、
RailsのMysql2が探すパスではなかった。
解決策:
1:
$ which mysql
mysqlのファイルがあるパスを特定
2:
$ ls
dylibファイルを見つける
3:ファイルを Railsがdylibファイルを探すファイルにコピペする
ーーーーーーーーーーーーー
その後、Rails サーバーを立ち上げようとするとエラー。
エラー0: mysql root のパスワードが違う
解決: 設定し直し
https://stackoverflow.com/questions/6474775/setting-the-mysql-root-user-password-on-os-x
エラー1:
Puma caught this error: Unknown database 'pomodoro-life_development' (ActiveRecord::NoDatabaseError)
エラー2:
$ rake db:migrate
rake aborted!
ActiveRecord::NoDatabaseError: Unknown database 'pomodoro-life_development'
Mysql2::Error: Unknown database 'pomodoro-lif...
解決:
$ bundle exec rake db:create
$ rake db:migrate
$ mysql.server start
参考: railsのapp作成でmysqlを使用する時の導入とハマるところ rake db:createができるまでの流れ - Qiita