lawup / nebulas-cat

a local development and debugging tool for Nebulas dapp

Home Page:https://tool.forfunapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

English

欢迎使用 Nebulas Cat 星云链 DAPP 本地开发调试工具,使用过程中遇到任何问题可以到 链社区 发帖交流。

使用教程

1. 下载 Nebulas Cat 源码 git clone https://github.com/xiwangzishi/nebulas-cat.git

2. 进入 nebulas-cat 文件夹,安装依赖 npm install

3. 运行工具(合约文件更新后,需要重启调试程序):

  • 方法一(推荐):使用 Visual Studio Code 的调试功能(可以在合约里面下断点) 调试 -> 启动调试
  • 方法二:运行工具 node index.js, 然后直接在合约里面使用 console.log 打印对应信息(会输出到控制台)

4. 设置chrome 插件钱包为 localhost 网络

5. 设置 Neb.js 网络为 localhost 网络(在你 DAPP 的 JS 代码中设置) neb.setRequest(new HttpRequest("http://localhost:8685"));

6. 设置 NebPay 的 queryPayInfo API callback为 localhost 网络(如果未使用该API则跳过,此处在你 DAPP 的 JS 代码中 NebPay.queryPayInfo 处设置)


NebPay.queryPayInfo(serialNumber,{
callback:'http://localhost:8685/api/pay',
listener:undefined
})

7. 用浏览器打开 nebulas-cat 目录下的 index.html 后输入 合约文件路径,点击 部署即可使用。

原理

其实就是本地起了一个 Web 服务(基于 Koa),然后实现了 Neb.js 请求节点的一些 API ,假装自己是个记账节点而已。

目前实现的 API 有:

  • /v1/user/nebstate
  • /v1/user/call
  • /v1/user/accountstate
  • /v1/user/rawtransaction
  • /v1/user/getTransactionReceipt
  • /v1/user/getEventsByHash
  • NebPay: /api/pay
  • NebPay: /api/pay/query

点击部署按钮,就是把输入的合约文件路径 require 进来作为 Node.js 的一个模块,然后 Neb.js 的请求都是直接调用合约实例的方法,所以可以直接利用 Visual Studio Code 来调试合约功能(理论上其他 IDE 也可以,自行摸索!)。具体的源码都在 index.js 中

本项目使用了一些官方 NVM 调试工具的一些源码

联系我:d2VjaGF0Onphbmtibw==

About

a local development and debugging tool for Nebulas dapp

https://tool.forfunapp.com


Languages

Language:JavaScript 75.6%Language:HTML 16.9%Language:CSS 7.5%Language:Shell 0.0%