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

Prerequisites

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
    1
    $ mkdir prq-webhook && cd prq-webhook
    Copied!
  • Initialize Node app
    1
    $ npm init
    Copied!
  • Create index.js
    1
    $ touch index.js
    Copied!
  • Install Express
    1
    $ npm install express
    Copied!
  • Put the following in index.js
    index.js
    1
    const express = require('express')
    2
    const app = express()
    3
    ​
    4
    app.use(express.json())
    5
    app.post('/', (req, res) => res.json(req.body))
    6
    ​
    7
    ​
    8
    const port = process.env.PORT || 3000
    9
    app.listen(port, () => console.log(Application listening on port ${port}))
    Copied!

Step 2 - Ngrok

  • Start Ngrok instance on port 3000
  • 1
    $ ngrok http 3000
    Copied!

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
  • 1
    $ node index.js
    Copied!
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
​
Last modified 2mo ago