When Starton sends a notification, Monitor sends an HTTP request to a web server. If your server is actually localhost, the request will fail. Starton cannot actually reach localhost. We need a tool to make that possible. The tool we're using is called ngrok.
Installing ngrok
- Go to Ngrok.
- Install ngrok on your system.
Launching your ngrok URL
- Launch your web application.
- Go to your localhost port. For example, http://localhost:3001.
- Launch
ngrok
with the commandngrok http 3001
. - Go to your Ngrok Web Interface http://127.0.0.1:4040.
- Click the
Status
tab. - Copy the URL of the tunnel which should look like this https://xxxxxxxx.ngrok.io.
Creating your watcher in Starton
You can use this Webhook URL in Starton to create your watcher.
- From Code
- From Webapp
To create a watcher from the code of you application, use the following snippet. You can find the full list of networks and event types in our API reference.
const axios = require("axios");
// First, authenticate to the API
const startonApi = axios.create({
baseURL: "https://api.starton.com",
headers: {
"x-api-key": "YOUR_API_KEY",
},
});
// Use the watcher creation endpoint
startonApi.post(
"/v3/watcher",
{
name: "Name of your watcher", // Enter a name for your watcher
description: "Describe your watcher", // Enter a description for your watcher
address: "0x000000000000", // Enter the address to watch (either a wallet or a smart contract)
network: "polygon-amoy",// Enter the network of your address.
type: "ADDRESS_ACTIVITY",// Select an event type
webhookUrl: "https://xxxxxxx/", // Here, enter the webhook url you got from ngrok.
confirmationsBlocks: 50 // Depending on your needs, select the number of confirmed blocks before an event triggers your watcher
}
).then((response) => {
console.log(response.data)
})
- From Dashboard, go to Watcher.
- Click + Watcher.
- Enter a Name and Description.
- Click Next.
- Select a type of notification.
- Fill in the Settings.
- In Construction:
- Select a Blockchain.
- Select a Network.
- Enter an address
- Enter a webhook URL. Here, enter the webhook url you got from ngrok.
- In Confirmation blocks, enter a number.
- Click Create.