How to Process Chainlink Price Feeds with Parsiq Smart Triggers in NodeJs Web Applications via Webhook Transport


Tutorial requires NodeJs, npm and Ngrock. Use the following resources to get these:
In this tutorial we demonstrate how to set up a Chainlink price feed Smart Trigger webhook for a NodeJs web application. In this example, we will be using Ngrok to expose a local environment port to the internet and then creating a Smart Trigger for sending Chainlink Oracle price feeds though a webhook.
We create a basic web application running on localhost:3000 which takes a message via POST method and sends confirmation in a response object. We then use a Chainlink price feed to create a Smart Trigger with a webhook to send to our application. We are using Express for processing our requests.

Step 1 - Create Web Application

  • Create a directory and cd into it
    $ mkdir prq-webhook && cd prq-webhook
  • Initialize Node app
    $ npm init
  • Create index.js
    $ touch index.js
  • Install Express
    $ npm install express
  • Put the following in index.js
    const express = require('express')
    const app = express()
    app.use(express.json())'/', (req, res) => res.json(req.body))
    const port = process.env.PORT || 3000
    app.listen(port, () => console.log(Application listening on port ${port}))

Step 2 - Ngrok

  • Start Ngrok instance on port 3000
  • $ ngrok http 3000

Step 3 - Create Webhook

  • Login to PARSIQ account. Create a webhook transport then set the ngrok forwarding address to the transport URL

Step 4 - Create Smart Trigger

Step 5 - Start Application and Deploy Smart Trigger

  • Run the node application and click 'Deploy' from the Smart Trigger page in PARSIQ account
  • $ node index.js
Chainlink Price Feed Smart Trigger
  • In a few minutes you should see the data from the smart trigger in your application.
Smart Trigger Price Feed Data in Application