node.js 获取以太坊合约事件

楚岳
2023-12-01

合约项目开发中一些记录需要通过合约中的事件中获得,可以用thegraph第三方, 但是分页有问题无法获取总条数, 还需要科学上网,也可以用node.js,获取到数据存到数据库中,查询方便,在去中心化和中心化相结合的项目起到重要作用。

//  引入WEB3

const Web3 = require('web3')
const fs = require('fs')
const DB = require('./mysqlDB')
const BigNumber = require('bignumber.js')
let investSql = 'insert into invest (user,amount,backAmount,time,hash) values (?,?,?,?,?)'
let investSelectSql = 'select * from invest where hash=?'
let swapSql = 'insert into swap (user,usdtAmount,tokenAmount,time,swapType,hash) values (?,?,?,?,?,?)'
let swapSelectSql = 'select * from swap where hash=?'
let withdrawSql = 'insert into withdraw (user,amount,time,hash) values (?,?,?,?)'
let withdrawSelectSql = 'select * from withdraw where hash=?'
let intrologSql = 'insert into introlog (user,intro,rewordIndex,startTime,stopTime,rewardAmo
 类似资料: