Skip to main content

Custom event(s)

Triggers when a smart contract emits one or multiple events you select from your ABI. To monitor events from a smart contract, the ABI of your contract must include events that are emitted.

caution

To use the custom events feature, you need to deploy or import your smart contract with Starton. For more information, see understanding smart contracts.

Creating a watcher from a custom event type

You can create a watcher to monitor blockchain event.

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 a network, you can find the list of networks available in our API reference.
type: "EVENT_CUSTOM", // Select the custom event type
customEventAbi: {}, // Here you will specify the event you want to monitor from the ABI of your contract.
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)
})

To emit events, your smart contract must contain an event and an emit.

For example, in the following contract, the setData event is emitted.

pragma solidity ^0.8.0;
contract SimpleStorage {
string data;

event dataSet(string _data);
constructor (string memory _data) {
data = _data;
}

function getData() public view returns(string memory) {
return data;
}

function setData(string memory _data) public returns(string memory) {
data = _data;
emit dataSet(_data);
return data;
}
}

Consequently the event in the ABI will include an object with the type "event", which is what you will enter as customEventABI:

[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "_data",
"type": "string"
}
],
"name": "dataSet",
"type": "event"
}
]
  • Creating a watcher from a custom event type