Skip to main content

EthTopic Event

In this tutorial, we will subscribe to an ERC20 contract Transfer event using the Arkhia API without the need to provide the contract address.

info

We will be using the Events API to create a new event subscription for a contract.

For subscribing to a contract event without specifying the contract address and ABI, follow these steps:

  1. Create a new item using the Create Item API.
  2. Update the item ABI file using the Update Item API.
  3. Update the item events using the Update Item API.
  4. Enable the item using the Enable Item API.

Copy the following code in your preferred language and replace the placeholders with your Arkhia API Key and Arkhia API Secret.

1. Create new Event Item
const axios = require('axios');const createApiUrl = `https://api.arkhia.io/events/hedera/create/ethtopic/<YOUR_ARKHIA_API_KEY>`;const apiSecret = `<YOUR_ARKHIA_API_SECRET>`;const headers = { headers: { "x-api-secret": apiSecret } };const createPayload = {    "item_id": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", // ethers.utils.id("Transfer(address,address,uint256)")    "network_id": 295}createItem = async () => {    try {        const response = await axios.post(createApiUrl, { scoutSettings: createPayload }, headers);        return response;    } catch (e) {        console.error(e);    }}createItem();
2. Update item ABI
const axios = require('axios');const updateAbiApiUrl = `https://api.arkhia.io/events/hedera/settings/update/contract/abi/<YOUR_ARKHIA_API_KEY>`;const apiSecret = `<YOUR_ARKHIA_API_SECRET>`;const headers = { headers: { "x-api-secret": apiSecret } };const updateAbiPayload = {    item_id: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",    network_id: 296,    config_type: "abi",    config_object: [        {            anonymous: false,            inputs: [                { indexed: true, internalType: "address", name: "owner", type: "address" },                { indexed: true, internalType: "address", name: "spender", type: "address" },                { indexed: false, internalType: "uint256", name: "value", type: "uint256" }            ],            name: "Approval",            type: "event"        },        {            anonymous: false,            inputs: [                { indexed: true, internalType: "address", name: "from", type: "address" },                { indexed: true, internalType: "address", name: "to", type: "address" },                { indexed: false, internalType: "uint256", name: "value", type: "uint256" }            ],            name: "Transfer",            type: "event"        }    ]}uploadAbi = async () => {    try {        const response = await axios.post(updateAbiApiUrl, { scoutSettings: updateAbiPayload }, headers);        return response;    } catch (e) {        console.error(e);    }}uploadAbi();
3. Add item event
const axios = require('axios');const updateEventUrl = `https://api.arkhia.io/events/hedera/settings/update/contract/events/<YOUR_ARKHIA_API_KEY>`;const apiSecret = `<YOUR_ARKHIA_API_SECRET>`;const headers = { headers: { "x-api-secret": apiSecret } };const addEvent = {    item_id: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",    network_id: 296,    config_type: "events",    config_object: [        {            eventId: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef_296_Transfer",            eventName: "Transfer",            eventRules: [                {                    ruleId: "Transfer_rule0",                    ruleName: "Transfer Rule0",                    enabled: true,                    email_notification: false,                    polling_interval: 1000,                    webhooks: [                        {                            tag: "My-Webhook",                            key: "my-webhook",                            value: "https://yet.another.webhook",                            type: "get",                            active: true                        }                    ],                    parameterCollection: [                        {                            enabled: false,                            parameterId: "Transfer_rule0_from",                            parameterName: "from",                            parameterType: "address",                            parameterRule: 1,                            parameterRuleValue: "",                            webhooks: []                        },                        {                            enabled: false,                            parameterId: "Transfer_rule0_to",                            parameterName: "to",                            parameterType: "address",                            parameterRule: 1,                            parameterRuleValue: "",                            webhooks: []                        },                        {                            enabled: true,                            parameterId: "Transfer_rule0_value",                            parameterName: "value",                            parameterType: "integer",                            parameterRule: 4,                            parameterRuleValue: "5000",                            webhooks: []                        }                    ]                }            ]        }    ]}updateEvent = async () => {    try {        const response = await axios.post(updateEventUrl, { scoutSettings: addEvent }, headers);        return response;    } catch (e) {        console.error(e);    }}updateEvent();
4. Enable item event
const axios = require('axios');const enableApiUrl = `https://api.arkhia.io/events/hedera/enable/contract/<YOUR_ARKHIA_API_KEY>`;const apiSecret = `<YOUR_ARKHIA_API_SECRET>`;const headers = { headers: { "x-api-secret": apiSecret } };const enablePayload = {    item_id: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',    network_id: 296}enableItem = async () => {    try {        const response = await axios.post(enableApiUrl, { scoutSettings: enablePayload }, headers);        return response;    } catch (e) {        console.error(e);    }}enableItem();