0

I want to use a node script that contains an events listener function (e.g. https://portal.thirdweb.com/sdk/advanced-features/contract-events#listen-to-all-events) inside my Next.js app.

As there is no server and the serverless functions need a trigger, I'm not sure where this kind of code should live.

How can I handle this case?

1
  • You could use a custom server in your Next.js app. Commented Nov 20, 2022 at 22:37

1 Answer 1

1

Any event listening should live on it's own server/not on serverless functions. The issue is that if you want to listen for events constantly and save them somewhere/act on it, the scripts that's listening for events needs to be constantly running.

With serverless functions (which is what all Next.js API endpoints are), they're only active when they get called, which won't work for event listening.

I would suggest building a simple Express server for event listening, and then deploying it somewhere like Zeet to have it always listening.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.