0

I have a deployed Smart Contract called rps.

I can listen to its events with this: https://web3js.readthedocs.io/en/v1.5.2/web3-eth-contract.html#events-allevents (which returns an eventEmitter)

I want to use this eventEmitter in my Express App.

My express app:

require("dotenv").config();

const express = require("express");
const app = express();
const mongoose = require("mongoose");

mongoose.connect(process.env.DATABASE_URL, {useNewUrlParser: true});
const db = mongoose.connection;
db.on("error", error => console.error(error));
db.once("open", () => console.log("Connected to Database"));

app.use(express.json());

const gamesRouter = require("./routes/games");
app.use("/games", gamesRouter);

app.listen(3000, () => console.log("Server Started"));

// ------------- LISTEN TO EVENTS -------------------

const rps = require("./rps");

rps.events.allEvents()
.on('data', event => {
    console.log("NEW EVENT:", event);
})

When I start the app, I see this: enter image description here

However, when I make transactions on my Smart Contract, nothing new gets logged.

I found these (but I don't think they are really what I'm looking for):

How can I use the eventEmitter while my express app is running?

I have a React app running in parallel with the same code, dependencies, inheritances and ABIs. All events show up there. So I'm sure my smart contract is emitting events, and I'm pretty sure there's nothing wrong with my rps variable. The problem should be related to my overall implementation in Express.

antoniopgs
  • 49
  • 2

0 Answers0