Skip to main content

🎥 Get Webhooks for Wallet Transactions via the QuickAlerts API

Created on
Updated on
Nov 26, 2024

2 min read

In this video, we go through the process of setting QuickAlerts to track wallet transactions via REST API in JavaScript.
Subscribe to our YouTube channel for more videos!

Following are the code examples shown in the video:

Creating a Wallet

Initiate a new file, wallet.js, to create a new wallet (skip this if you already have a wallet you want to track transactions for).

const ethers = require('ethers');

const wallet = ethers.Wallet.createRandom();
console.log(wallet);

Getting QuickAlerts API key

We will be working with QuickAlerts REST API. To access the API, we will need the QuickAlerts API key.

To get your QuickAlerts API key you will need a QuickNode account, if you don't already have one you can create one for free. To generate an API key, you can follow the directions here. Be sure to configure the key with access to QUICKALERTS_REST.

Setting Up a WebHook Destination

Create a new file, destination.js, to create a QuickAlerts WebHook destination.

var myHeaders = new Headers()
myHeaders.append('content-type', 'application/json')
myHeaders.append('x-api-key', 'YOUR_QUICKALERTS_API_KEY')

var requestOptions = {
method: 'POST',
headers: myHeaders,
redirect: 'follow',
body: JSON.stringify({
name: 'YOUR_DESTINATION_NAME',
to_url: 'YOUR_WEBHOOK_URL',
webhook_type: 'POST',
service: 'webhook',
payload_type: 1,
}),
}

fetch(
'https://api.quicknode.com/quickalerts/rest/v1/destinations',
requestOptions
)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error))

Replace YOUR_QUICKALERTS_API_KEY with your QuickAlerts API key which you get from the QuickAlerts dashboard, YOUR_DESTINATION_NAME with destination name of your choice, and YOUR_WEBHOOK_URL with your WebHook URL where you want to send your alert.

Deploying the Alert

Create a new file, notifcation.js, to setup an alert.

const axios = require('axios');

let data = JSON.stringify({
"name": "YOUR_NOTIFICATION_NAME",
"expression": "YOUR_BASE64_ENCODED_EXPRESSION",
"network": "ethereum-sepolia",
"destinationIds": [
"DESTINATION_ID"
]
});

let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.quicknode.com/quickalerts/rest/v1/notifications',
headers: {
'accept': '*/*',
'Content-Type': 'application/json',
'x-api-key': 'YOUR_QUICKALERTS_API_KEY'
},
data : data
};

axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});

Replace YOUR_NOTIFICATION_NAME with a desired name for your alert, YOUR_BASE64_ENCODED_EXPRESSION with your QuickAlerts expression in BASE64 encoded format, DESTINATION_ID with the destination id you got after running destination.js, and YOUR_QUICKALERTS_API_KEY with your QuickAlerts API key.

We ❤️ Feedback!

Let us know if you have any feedback or requests for new topics. We'd love to hear from you.

Share this guide