Skip to main content
Tutorial
Beginner

Monitoring blockchain activity

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

not a developer?

To follow this tutorial, you will need coding experience. If it's not your case, you can still create a watcher:

Step 1 - Initialize the project

  1. Start by creating a directory for your project.

    mkdir monitor-blockchain
  2. Then, get into your project directory.

    cd monitor-blockchain
  3. With your project directory set up, install the dependencies.

    npm add axios

This library will allow you to make request to the Starton API. For more information on axios, check out Axios documentation.

  1. Then, usetouch to create a index.js file and open it with your favorite editor.

    touch list.js

Step 2 - Add Starton to your project

  1. First, import axios.

    const axios = require("axios")
  2. Then, initialize axios using Starton URL and authenticate with your API KEY.

    Create an API key


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

Step 3 - Creating a watcher

What is a Watcher?

A watcher is a powerful tool that lets you monitor blockchain events in real-time. With Starton, you can set up watchers to monitor activities such as address activities, balance changes, or even smart contract events.

  1. Set up the watcher parameters

    // Let's create your watcher
    starton
    .post("/v3/watcher", {
    name: "Name of your watcher",
    type: "ADDRESS_ACTIVITY",
    address: "0x000000000000",
    network: "polygon-amoy",
    webhookUrl: "https://xxxxxxx/",
    confirmationsBlocks: 50,
    })
    .then((response) => {
    console.log(response.data)
    })
    .catch((error) => console.error(error.response.data))

    Let's go through the parameters provided to create a watcher:

    • name: This field specifies the name of your watcher. Useful for identification purposes, especially if you have multiple watchers set up for the same address or contract at different confirmation speeds different confirmation speeds.
    • type: The type of blockchain event that you want the watcher to monitor. The ADDRESS_ACTIVITY type, in this context, means the watcher will monitor and notify of any activity related to the provided address but Starton provides you with a list of events as well as the possibility to watch events from your own custom contract .
    • address: This is the specific blockchain address you want to monitor. It can be a wallet address or a smart contract address, depending on the event type you chose.
    • network: This specifies the blockchain network on which is the given address. In the provided example, polygon-amoy refers to the amoy testnet of the Polygon (previously known as Matic) network. For more, see Supported Networks.
    • webhookUrl: This URL is where the notifications will be sent when the watched event occurs. Essentially, once the watcher detects the specified event on the blockchain, it will send an HTTP POST request to this URL with details of the event. You can use https://webhook.site/ or test a webhook on your local environment using ngrok.
    • confirmationsBlocks: This is the number of confirmed blocks before an event triggers the watcher. It's a safety measure to ensure that the event (like a transaction) is well-confirmed on the blockchain and is not likely to be reversed. The higher the number, the more confirmations are required, and vice versa. Each network has its own default confirmation blocks number, for more information, see Understanding confirmation blocks.
  2. Almost done! Now we can execute it to get our first watcher!

    node list.js

And just like that, your first watcher is now live on Starton!


Check all triggered events on Starton Web Application



Congratulations on creating your first watcher! In this tutorial, you discovered how to monitor blockchain activity but this is only the first step.

What's next?

Learn how to:

Loubna Benzaama

Lead technical writer


Created:

April 3, 2024

Reading time:

5 min


Content
  • Step 1 - Initialize the project
  • Step 2 - Add Starton to your project
  • Step 3 - Creating a watcher
  • What's next?