> For the complete documentation index, see [llms.txt](https://505876833.gitbook.io/gao-jin-yun-xin-xin-yong-chi-v1.0/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://505876833.gitbook.io/gao-jin-yun-xin-xin-yong-chi-v1.0/ping-tai-bu-shu/jian-ting-jiao-ben.md).

# 监听脚本

将链上事件按照设计的逻辑保存在本地数据中

### 环境需要

```
sudo apt-get install mongodb 
```

### 环境配置

1. 数据库配置

```
// 创建所需要的数据库
mongo
use GJYX // 创建或打开数据库
// 创建集合
db.createCollection('grants');
db.createCollection('infos');
db.createCollection('members');
db.createCollection('transactions');
// mongodb 常用命令参考：https://www.runoob.com/mongodb/mongodb-tutorial.html
```

&#x20; 2\. 监听RPC配置

```
cd service
vi Run.js // 也可以在代码编辑器里直接修改
// 将里面的 RPC 替换为合约部署链相应的 RPC
const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");
// Mongodb 启动的端口，一般默认即可
const url = "mongodb://127.0.0.1:27017";
```

### 启动

```
cd service 
npm install 
nohup node --experimental-json-modules Run.js > myLog.log 2>&1 & // 后台运行，将打印的日志保存在 MyLog.log 中
```

{% hint style="info" %}
演示时部署出错是因为使用了旧版本的合约的ABI，现在已替换为最新，在 /utils/contractABI 下，若对合约功能进行了修改，请将重新编译好的MainSystem的ABI （位置为/build/contracts/MainSystem.json）替换旧文件。
{% endhint %}
