Skip to content

Commit 6393560

Browse files
committed
docs: add webhooks section to agents and LLMs documentation (#7317)
# [Portal] Feature: Add Webhooks Documentation for AI Agents + Example with multiple ABIs for decoding ## Notes for the reviewer Example with multiple ABIs for decoding ([related PR](https://app.graphite.dev/github/pr/thirdweb-dev/insight-service/268/fix-improve-ABI-validation-to-support-array-format)) 1. Added examples on creating events filters with multiple ABI options Also, this PR adds comprehensive documentation about using webhooks with AI agents in the Insight platform. The documentation covers: 1. Use cases for webhooks with AI agents 2. How to create and manage webhooks 3. Filtering capabilities, including support for multiple ABIs 4. Information about webhook payloads <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Added a new "Webhooks" section describing how to use webhooks with the Insight API for real-time blockchain event notifications and event-driven AI agents. - Provided use cases, filter examples, and links to detailed webhook and payload documentation. - Enhanced webhook filter documentation to clarify support for multiple ABIs, including examples for handling ERC-20 and ERC-721 Transfer events. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 62af256 commit 6393560

File tree

3 files changed

+119
-13
lines changed

3 files changed

+119
-13
lines changed

apps/portal/src/app/insight/agents-and-llms/llmstxt/page.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,46 @@ async function safeApiCall() {
319319
}
320320
```
321321

322+
## Webhooks
323+
324+
Webhooks allow you to receive notifications when specific blockchain events or transactions occur. This enables you to build event-driven AI agents that can react to on-chain activity in real-time.
325+
326+
### Use Cases for AI Agents
327+
328+
- **Real-time Monitoring**: An agent can monitor for specific events (e.g., a large transfer to a whale wallet) and trigger alerts or other actions.
329+
- **Automated Workflows**: When a specific on-chain action occurs (e.g., a new NFT is minted), an agent can automatically kick off a downstream process, like updating a database or sending a notification.
330+
- **Data Aggregation**: Use webhooks to feed on-chain data into a vector database or other data store for later analysis by an LLM.
331+
332+
### Creating a Webhook
333+
334+
Webhooks are created and managed via the Insight API. You can find more details in the [Managing Webhooks documentation](/insight/webhooks/managing-webhooks).
335+
336+
### Filtering
337+
338+
You can create powerful filters to specify exactly which events or transactions you want to be notified about.
339+
340+
For example, to receive a notification for both ERC-20 and ERC-721 `Transfer` events, you can use a filter like this:
341+
342+
```typescript
343+
{
344+
"v1.events": {
345+
"chain_ids": ["1"],
346+
"signatures": [
347+
{
348+
"sig_hash": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
349+
"abi": "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}]"
350+
}
351+
]
352+
}
353+
}
354+
```
355+
356+
This allows an agent to monitor multiple token standards with a single webhook. For more on filtering, see the [Filtering documentation](/insight/webhooks/filtering).
357+
358+
### Payload
359+
360+
The webhook payload contains the event or transaction data. Your agent will need to parse this payload to extract the relevant information. See the [Payload documentation](/insight/webhooks/payload) for details on the payload structure.
361+
322362
## API Reference
323363

324364
### Events API

apps/portal/src/app/insight/agents-and-llms/page.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,44 @@ async function safeApiCall() {
342342
}
343343
```
344344

345+
## Webhooks
346+
347+
Webhooks are a powerful tool for building event-driven AI agents that can react to on-chain activity in real-time. By subscribing to specific blockchain events or transactions, your agent can receive notifications and trigger automated workflows.
348+
349+
### Use Cases for AI Agents
350+
351+
- **Real-time Monitoring**: An agent can monitor for specific events (e.g., a large transfer to a whale wallet) and trigger alerts or other actions.
352+
- **Automated Workflows**: When a specific on-chain action occurs (e.g., a new NFT is minted), an agent can automatically kick off a downstream process, like updating a database or sending a notification.
353+
- **Data Aggregation**: Use webhooks to feed on-chain data into a vector database or other data store for later analysis by an LLM.
354+
355+
### Getting Started with Webhooks
356+
357+
To get started, you can create and manage webhooks through the Insight API. For detailed instructions, refer to the [Managing Webhooks documentation](/insight/webhooks/managing-webhooks).
358+
359+
### Filtering Events
360+
361+
Insight's webhooks feature a powerful filtering system that lets you subscribe to only the events and transactions you care about. For example, you can create a single webhook that notifies your agent of both ERC-20 and ERC-721 `Transfer` events by providing multiple ABIs in the filter.
362+
363+
```typescript
364+
{
365+
"v1.events": {
366+
"chain_ids": ["1"],
367+
"signatures": [
368+
{
369+
"sig_hash": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
370+
"abi": "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}]"
371+
}
372+
]
373+
}
374+
}
375+
```
376+
377+
For more advanced filtering options, see the [Filtering documentation](/insight/webhooks/filtering).
378+
379+
### Understanding the Payload
380+
381+
When a webhook is triggered, it sends a payload to your specified endpoint. This payload contains the event or transaction data that your agent will need to process. To learn more about the structure of this payload, see the [Payload documentation](/insight/webhooks/payload).
382+
345383
## API Reference
346384

347385
### Events API

apps/portal/src/app/insight/webhooks/filtering/page.mdx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Each webhook must have either an events filter or a transactions filter (or both
3030
```typescript
3131
{
3232
"v1.events": {
33-
chain_ids: string[], // Filter by specific chains
34-
addresses: string[], // Filter by contract addresses
35-
signatures: { // Filter by event signatures
36-
sig_hash: string, // Event signature hash
37-
abi?: string, // Optional ABI for data decoding
38-
params?: Record<string, string | number> // Filter on decoded parameters
33+
chain_ids: string[], // Filter by specific chains
34+
addresses: string[], // Filter by contract addresses
35+
signatures: { // Filter by event signatures
36+
sig_hash: string, // Event signature hash
37+
abi?: string, // Optional: A single ABI object or an array of ABI objects as a string for data decoding
38+
params?: Record<string, string | number> // Filter on decoded parameters
3939
}[]
4040
}
4141
}
@@ -45,13 +45,13 @@ Each webhook must have either an events filter or a transactions filter (or both
4545
```typescript
4646
{
4747
"v1.transactions": {
48-
chain_ids: string[], // Filter by specific chains
49-
from_addresses: string[], // Filter by sender addresses
50-
to_addresses: string[], // Filter by recipient addresses
51-
signatures: { // Filter by function signatures
52-
sig_hash: string, // Function signature hash
53-
abi?: string, // Optional ABI for data decoding
54-
params?: Record<string, string | number> // Filter on decoded parameters
48+
chain_ids: string[], // Filter by specific chains
49+
from_addresses: string[], // Filter by sender addresses
50+
to_addresses: string[], // Filter by recipient addresses
51+
signatures: { // Filter by function signatures
52+
sig_hash: string, // Function signature hash
53+
abi?: string, // Optional: A single ABI object or an array of ABI objects as a string for data decoding
54+
params?: Record<string, string | number> // Filter on decoded parameters
5555
}[]
5656
}
5757
}
@@ -82,6 +82,34 @@ The following example will filter for `Transfer` events on Ethereum for the cont
8282
}
8383
```
8484

85+
### Supporting Multiple Event ABIs
86+
87+
In some cases, different token standards use the same event signature. For example, both ERC-20 and ERC-721 standards have a `Transfer` event. The ERC-20 `Transfer(address,address,uint256)` event has a non-indexed `value` parameter, while the ERC-721 `Transfer(address,address,uint256)` has an indexed `tokenId` parameter.
88+
89+
To support these scenarios, you can provide an array of ABIs in the `abi` field. This allows the webhook to attempt decoding with each ABI until one succeeds.
90+
91+
The `abi` field accepts a string that can be either a single JSON object `"{}"` or a JSON array of objects `'[{},{}]'`.
92+
93+
Here is an example of a webhook that filters for both ERC-20 and ERC-721 `Transfer` events across all contracts on the Ethereum mainnet:
94+
95+
```typescript
96+
{
97+
...
98+
"filters": {
99+
"v1.events": {
100+
"chain_ids": ["1"],
101+
"signatures": [
102+
{
103+
"sig_hash": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
104+
"abi": "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}]"
105+
}
106+
]
107+
}
108+
}
109+
...
110+
}
111+
```
112+
85113
And this example will filter for `Approve` function calls on Ethereum for the contract `0x1f9840a85d5af5bf1d1762f925bdaddc4201f984`
86114
```typescript
87115
{

0 commit comments

Comments
 (0)