Web3Hooks API
Web3Hooks

Web3Hooks

Overview

The Web3Hooks API is divided into four endpoints: Create Hook, Get Hook, List Hooks, and Delete Hook. The Create Hook endpoint allows you to create hooks that can be configured to track log events or function calls as they happen. Instant notifications are delivered to a designated webhook URL. The Get Hook endpoint allows seeing the details of a particular hook by specifying its id. The List Hooks endpoint provides an in-depth view of all currently active hooks to track the configuration and status of each hook. The Delete Hook endpoint is used to delete hooks that are no longer required. To delete a hook, you will need its id, which can be obtained using the List Hooks or Show Hook endpoints. The id can also be found in the output after creating a hook.

📘️

Multiple values can be set for these parameters: topic_0, topic_1, topic_2, topic_3, sig_hash, and contract, with a maximum of five items each.

Parsiq JS Authentication & Confirmations

There are two ways of authentication via Parsiq JS Client: HttpAuthType.basic and HttpAuthType.bearer. The former is the classic username and password, whereas the latter is the user's bearer token. In the Usage section, while creating a hook, you can see examples of both authentication methods in the parsiq.js by events and parsiq.js by calls tabs.

The confirmations field allows users to specify the number of confirmations a transaction or event must have before triggering a delivery to the webhook. The value should be in the range of 1 to 12. The reasons you might prefer to use the confirmations fields are as follows:

  • to reduce false positives;
  • to ensure the integrity and security of the event or call being monitored;
  • to balance between the security provided by confirmations and the need for quick responsiveness;
  • to avoid chain reorganizations, mitigating the risk of reacting to events or calls on blocks that may be part of a temporary fork.

Usage

In this example, we create a monitoring hook for every transfer made within the PRQ token's smart contract.

import * as Parsiq from '@parsiq/parsiq.js';
import {HttpAuthType, OpCode} from '@parsiq/parsiq.js';
 
const client = Parsiq.createClient(process.env.API_KEY, Parsiq.ChainId.ETH_MAINNET);
 
const stream = await client.web3Hooks.create({
    name: 'PRQ Token Hook',
    description: 'Get all transfers within the PRQ token smart contract',
    confirmations: 12,
    endpoint_url: 'https://webhook.site/271ea63d-a6d7-4b43-8e43-e088abc3072f',
    endpoint_auth:
        {
          type: HttpAuthType.basic,
          credentials: {
              username: 'user',
              password: 'qwerty'
            },
        },
    filter_type: 'events',
    criteria:
        {
          contract: ['0x362bc847A3a9637d3af6624EeC853618a43ed7D2'],
          topic_0: ['0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0'],
          topic_1: [''],
          topic_2: [''],
          topic_3: [''],
          origin: '',
          op_code: OpCode.LOG3
        }
})
console.log(stream)

Output:

{
    '31bcee1f-a98b-4427-af7a-3c66caa125e5'
}

Parameters

Path params
chainId
string
REQUIRED
version
string
REQUIRED
Body params
name
string
REQUIRED
description
string
confirmations
number
endpoint_url
string
REQUIRED
endpoint_auth
object
filter_type
string
REQUIRED
contract
array of strings
origin
string
topic_0
array of strings
topic_1
array of strings
topic_2
array of strings
topic_3
array of strings
op_code
string
OR
sig_hash
array of strings
sender
string
include_events
boolean