-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const feathers = require('@feathersjs/feathers')
const express = require('@feathersjs/express')
const app = express(feathers())
const Web3 = require('web3')
const wsProvider = new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/_ws')
const web3 = new Web3(wsProvider)
wsProvider.on('connect', function() {
console.log('Connected to Web3!')
})
const TransferEventTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
const contracts = new Set()
web3.eth.subscribe(
'logs',
{ fromBlock: 'latest', toBlock: 'pending', topics: [TransferEventTopic] },
(error, result) => {
if (error) console.log(error)
console.log(result)
if (result.address) {
contracts.add(result.address)
}
}
)
app.use(express.json()) // Turn on JSON body parsing for REST services
app.use(express.urlencoded({ extended: true })) // Turn on URL-encoded body parsing for REST services
app.configure(express.rest()) // Set up REST transport using Express
app.use(express.errorHandler()) // Set up an error handler that gives us nicer errors
app.use('contracts', {
async get(name) {
return [...contracts]
}
})
app.listen(3030)