2018-03-28 RSK开发环境搭建

RSK开发环境搭建

1、操作系统用的ubuntu16,用virtualbox安装的

2、搭建以太坊开发环境,参考https://mshk.top/2017/11/truffle-4-0-geth-1-7-2-testrpc/

因为rsk是拿以太坊环境开发智能合约的,因此这块必需先跑通

3、rsk代码环境,参考https://github.com/rsksmart/rskj/wiki/RSK-node-on-Linux

我安装的是eclipse,没有使用收费的IntelliJ IDEA 

a、拉取代码

make rsk & cd rsk

git clone --recursive https://github.com/rsksmart/rskj.gitcd rskj

git checkout tags/BAMBOO-0.4.1 -b master

b、执行./configure.sh

否则会缺少一些必要的库

c、使用eclipse导入grade项目运行后

可以看代码目录下logs目录下的日志,查看错误信息虚拟机必需能够直连网络,不能通过代理上网

4、配置rsk为regtest环境,参考https://github.com/rsksmart/rskj/wiki/Get-your-Standalone-RSK-Node-(RegTest)

运行后查看日志,可以看到有挖矿,这样后续步骤就不愁发布合约的费用了

5、发布合约


参考https://github.com/rsksmart/tutorials/wiki里面module1-4部分把合约先发布到以太坊的测试环境验证没有问题,这里我参考文章实现了自己的dapp,目录为rskdemo

然后参考module5,https://github.com/rsksmart/tutorials/wiki/Module-5-%E2%80%93-Smart-contract-on-RSK-(50-minutes),这个里面有些错误,需要注意

a、修改truffle.js

module.exports = {

networks : {

rsk: {

gas : 2500000,

gasPrice : 1,

from : "0xc702ea7a0404aa9b34ab0e4f10abda4ae3b809ed",

host : "localhost",

port : 4444,

network_id : "*" // Match any network id

}

}

};

b、truffle console --network rsk

在这里主要是给truffle.js里面配置的地址"0xc702ea7a0404aa9b34ab0e4f10abda4ae3b809ed"转账

如果没有eth后面发布的合约会出现下面的错误:

truffle migrate --reset --network rskUsing network 'rsk'.Running migration: 1_initial_migration.jsDeploying Migrations...... undefinedError encountered, bailing. Network state unknown. Review successful transactions manually.Error: From address private key could not be found in this nodeat Object.InvalidResponse (/usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)at /usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:225:1at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)at IncomingMessage. (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)

at emitNone (events.js:111:20)

at IncomingMessage.emit (events.js:208:7)

at endReadableNT (_stream_readable.js:1064:12)

at _combinedTickCallback (internal/process/next_tick.js:138:11)

at process._tickCallback (internal/process/next_tick.js:180:9)

执行以下命令转账:

web3.eth.blockNumber

web3.eth.accounts

web3.eth.getBalance(web3.eth.accounts[0])

web3.eth.sendTransaction({from:web3.eth.accounts[0],to:web3.eth.accounts[10],value:web3.toWei(5,'ether')})

web3.eth.getBalance(web3.eth.accounts[10])

这里的账户编号10就是我们自己配置在conf里面的账户

c、发布合约

新打开一个terminal终端,进入rskdemo目录,执行truffle migrate --reset --network rsk

这个过程出现过两个错误,一个就是上面因为没有eth出现的Error: From address private key could not be found in this node;

另外一个错误是:

truffle migrate --network rsk --resetUsing network 'rsk'.Running migration: 1_initial_migration.js Deploying Migrations... ... undefinedError encountered, bailing. Network state unknown. Review successful transactions manually.Error: Local wallet is disabled in this node at Object.InvalidResponse (/usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1) at /usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1 at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:225:1 at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1 at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1) at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1) at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1) at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1) at IncomingMessage. (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)

    at emitNone (events.js:110:20)

    at IncomingMessage.emit (events.js:207:7)

    at endReadableNT (_stream_readable.js:1057:12)

    at _combinedTickCallback (internal/process/next_tick.js:138:11)

    at process._tickCallback (internal/process/next_tick.js:180:9)

这个错误如果参考步骤4实现了regtest测试环境,就不会出现问题,其原因是本地钱包功能没有打开

当我们看到下面的信息的时候,就是发布成功了

truffle migrate --reset --network rskUsing network 'rsk'.

Running migration: 1_initial_migration.js

  Deploying Migrations...

  ... 0xdb59186695cde97d6e487cb6237d30ce9a1811dabb43a9cb006179e42b77ca14

  Migrations: 0xa1d1bb14e5ae204229f8ea58de20b7444596ec3c

  Deploying HelloWorld...

  ... 0x43bcd6f6eb401f6e0819e73f75cdf85147e55784d170ebafdcf59c579864ab9f

  HelloWorld: 0x3cc6f8881453e1125111eb3632a08626de37c8ec

Saving successful migration to network...

  ... 0x7652ef0a895e9bde67bc8d4bbcceee00658892f3645fbfc696252e1ab914567e

Saving artifacts...

如果没有成功,建议去https://gitter.im/rsksmart/rskj提问,他们一般晚上答复,和我们作息时间不一致

d、测试合约

这个时候需要关闭前面的truffle console --network rsk,然后重新执行truffle console --network rsk

然后执行以下命令:

var contract;

HelloWorld.deployed().then(function(instance){contract= instance;});

contract.getGreeting()

contract.setGreeting("test")

contract.getGreeting()

如果contract.getGreeting()能够正确输出数据,测试就成功了   

你可能感兴趣的:(2018-03-28 RSK开发环境搭建)