美文网首页
2018-05-09 ethereum-harmony 使用

2018-05-09 ethereum-harmony 使用

作者: oracle3 | 来源:发表于2018-05-09 17:26 被阅读0次

ethereum-harmony 使用

ethereum-harmony使用了EthereumJ来演示以太坊的运行,具体参考https://github.com/ether-camp/ethereum-harmony

其eclipse工程的搭建有点难度,这里记录一下

1、下载代码

git clone https://github.com/ether-camp/ethereum-harmony

如果只是使用gradle编译就比较简单,

cd ethereum-harmony

gradlew runPrivate

直到出现http://localhost:8080提示,就可以在浏览器打开http://localhost:8080

然后通过rpc操作,rpc相关操作可以参考基于以太坊的RPC智能合约入门 - ethereumj(http://orchome.com/878)

2、安装lombok

参考eclipse安装lombok(https://blog.csdn.net/dorothy1224/article/details/79280591/)

3、打开eclipse,安装插件buildship

参考eclipse导入Gradle项目(https://www.cnblogs.com/lixuwu/p/6692371.html)

目前eclipse可以直接导入gradle工程,因此这个插件可以不安装

4、导入ethereum-harmony

右键工程,选择properties-java compiler-errors/warnings-Deprecated and restricted API-Forbidden reference(access rules):

把error改Warning

5、运行

右键工程,run as java application,选择Main class: com.ethercamp.harmony.Application

设置VM arguments:

-server -Xss2M -XX:+UseCompressedOops -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Dethereumj.conf.res=private.conf -Ddatabase.name=database-private -DnetworkProfile=private -Xmx3500M

运行直到出现http://localhost:8080

这个时候在浏览器打开http://localhost:8080就可以了

6、异常情况

在windows使用curl会出现下面的错误,

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' http://localhost:8545/rpc

{"jsonrpc":"2.0","id":"null","error":{"code":-32700,"message":"JSON parse error"}}

参考文章

https://ethereum.stackexchange.com/questions/23523/curl-jsonrpc-to-localhost8545/38134#38134

使用以下方法规避

curl -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_accounts\",\"params\":[],\"id\":67}" http://localhost:8545/rpc

或者

echo {"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1} | curl -d @- -H "Content-Type: application/json" -X POST http://localhost:8545/rpc

如果使用Postman工具就不需要考虑平台问题了

7、运行中遇到的几个问题

a、不挖矿就不可能搞交易,因此挖矿必须打开,修改代码

com.ethercamp.harmony.Application.main(String[]) 中

config.overrideParams("mine.start", "true");

b、web.enabled 配置找不到

修改代码:com.ethercamp.harmony.config.HarmonyProperties.isWebEnabled()

return true;

c、rpc.enabled 配置找不到

修改代码:com.ethercamp.harmony.config.HarmonyProperties.isRpcEnabled()

return true;

d、帐号没钱

修改src\main\resources\genesis\genesis-private.json中的alloc部分,把自己的账户加入,重新启动。

8、运行命令

浏览器中输入http://localhost:8080,打开后出现区块浏览界面,可以在terminal输入命令:

node> eth_accounts

[]

node> personal_newAccount 123

"0x76a5bf8fc57f3e07525ade42bc33c0e5b5224c3d"

node> eth_accounts

[

  "0x76a5bf8fc57f3e07525ade42bc33c0e5b5224c3d"

]

node> miner_setEtherbase 0x76a5bf8fc57f3e07525ade42bc33c0e5b5224c3d

true

node> eth_getBalance 0x76a5bf8fc57f3e07525ade42bc33c0e5b5224c3d latest

"0x32afbb4a285e3c0000"

node> personal_newAccount 123

"0xeef13bbcb9cb89f495f5485ea3fdb302109c1ac8"

node> personal_unlockAccount 0x76a5bf8fc57f3e07525ade42bc33c0e5b5224c3d 123 30

true

当然这个操作好复杂,不如直接打开postman,post http://localhost:8080/rpc 处理更简单

相关文章

  • 2018-05-09 ethereum-harmony 使用

    ethereum-harmony 使用 ethereum-harmony使用了EthereumJ来演示以太坊的运行...

  • 2018-05-09

    2018-05-09

  • 2018-05-09

    2018-05-09 戴师傅简书作者 2018-05-09 21:10 打开App (稻盛哲学学习会)打卡第54天...

  • selenium+js处理display属性为none

    Author='jolting' Date='2018-05-09' 故事and事故 故事是这样开始的,正在写自动...

  • Gone with the wind

    2018-05-09 周三 早上晨练,看到满草坪的蒲公英,心里升腾起柔...

  • 520情话-我必生死相依

    浅水涅槃 2018-05-09 10:07 · 字数 7324 · 阅读 96 · 原谅我喜欢你好多年 261 遇...

  • TF1-1第1次

    【时间】2018-05-09 【地点】福田锦囊寓酒店 【级别】TF1-1第1次 【自我感受】 【钻石反馈】 ...

  • 日精进打卡(第306天)

    2018-05-09 姓名:李义 公司:........ 组别:259期利他二组 【知~学习】 背诵 六项精进大纲...

  • neo4安装

    2018-05-09 安装 1.当然是下载了 neo4j-desktop-offline-1.1.0-x86_64...

  • selenium处理鼠标事件

    author='jolting' date='2018-05-09' 好久没更了,最近有项目测试,需要写自动化用例...

网友评论

      本文标题:2018-05-09 ethereum-harmony 使用

      本文链接:https://www.haomeiwen.com/subject/sqdorftx.html