Skip to main content

Monitoring blockchain activity

With Starton, you can monitor blockchain activity. Whether it's to watch the activity of a wallet or a smart contract, you can create watchers, triggered by events.

Let's integrate blockchain into your application project to track the activity of an address using Starton. You can also create watchers from Dashboard, see Creating a watcher.

An event is a set of conditions that are checked when a block is inspected.

When the conditions of a watcher are met, the watcher triggers and sends a communication to the webhook given during the watcher's creation.

You will need:

Creating an Application project

  1. Create a directory for your app.
  2. Create a directory named src.
  3. In your terminal, install the express package using npm i express
  4. In src, create a index.js file.
  5. In index.js, enter the following lines to set up a port for your project:
const express = require("express")
const routes = require("./routes")
const app = express()
app.use(bodyParser.json())
const port = 3001 // Port of the project

app.set("port", port) // Set the port of the project
app.use("/", routes)
app.listen(port, () => {
console.log(`Server listening on port ${port}`)
})

This will deploy your app on port 3001.

Now for the good part, let's connect Starton to your application.

Connecting Starton to your application

  1. In src, create a routes.js file.

    const express = require("express")
    const axios = require("axios")
    const router = express.Router()
  2. In it, first authenticate with your API KEY.

    // AUTHENTICATING TO THE API USING YOUR API KEY
    const startonApi = axios.create({
    baseURL: "https://api.starton.com",
    headers: {
    "x-api-key": "YOUR API KEY ",
    },
    })

Creating a watcher

To create a watcher from the code of your application, use the following snippet. You can find the full list of networks and event types in our API reference.

// 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-mumbai",// Enter a network, you can find the list of networks available in our API reference.
type: "ADDRESS_ACTIVITY",// Select an event type
webhookUrl: "https://xxxxxxx/", // Enter the address of the webhook
confirmationsBlocks: 50 // Depending on your needs, select the number of confirmed blocks before an event triggers your watcher
}
).then((response) => {
console.log(response.data)
})
  1. Display a message on your localhost:3001 to inform you that the transaction is successful.

    router.get("/", (req, res) => {
    res.send("Upload successful")
    })

    module.exports = router

Starting your application

  1. In your terminal, run node src.

You uploaded your first watcher with Starton. Congratulations!