[SOLVED] How can I setup Moralis webhook?

I have a moralis dashboard & database with 2 tables which get the data from smart contract events.
I want to trigger a function in an external express server running in some domain (https://xyz.com) whenever new data is added to the Transfer table (on beforeSave event)

I used the webhook tab in the dashboard and added all the data. But its not working.

How can I achieve something like that?
Do I need to use cloud function for this? Please help.

Can you post your Express code? What do you do to test if the endpoint was called or not e.g. log a message?

Is your server exposed and reachable remotely? If you set up an endpoint on the Express server and call it using “webhook URL” (which is the domain of the server + route name), it should work.

@alex Thanks for the response.

My express server serves just a basic endpoint that accepts a get request.

app.get("/", (req, res) => {
 console.log({ headers: req.headers, body: req.body });
 res.status(200).send({ success: true });
});

I ran the server to test if the webhook is working & see the data, but I don’t see any request coming from the webhook during the specified event (beforeSave).

Is your server exposed and reachable remotely?

I think so, since I can manually make get requests to that endpoint.

It needs to be POST, not GET it looks like.

1 Like

@alex
thanks so much. I didn’t know that. I can see the requests now.

Also, I ran into another problem, I receive three different requests for a single blockchain event when using beforeSave webhook. If I wait for the confirmed value to be true, then it takes very long time(i.e 3 to 4 minutes).
What should I do?

That delay is expected for confirmed value.

You will me able to use streams api soon:


This api is specific to making webhook requests to your own backend.
1 Like

@cryptokid thanks
When will this be out?

It is expected next week