If you prefer a no-code way to add webhooks that uses the Sequence Builder, check out this walkthrough.
If you require a server for development, you can use the following:Template Nodejs Webhook Server combined with ngrok a secure tunnel to your computer running the local server
1. Register a Webhook Listener
Our filters allow you to listen to on-chain events for particular contract addresses, contract events, specific token ids, account addresses, or topic hashes.If you require a webhook endpoint to call, you can use webhook.site for testing purposes to specify used in the
url
field.AddWebhookListener
Method: with required*
fields
- Request: POST /rpc/Indexer/AddWebhookListener
- Content-Type: application/json
- Body (in JSON):
url*
(string) — the URL to send the webhook tofilters*
(object) — an object of filterscontractAddresses*
([]string) — an array of any contract addressevents*
([]string)— any contract event, with the includedindexed
keyword from the contract when necessary (e.g.Transfer(address indexed from, address indexed to, uint256 amount)
. Shorthand is also acceptable without argument names, which will simply be parsed as: arg1, arg2, etc. i.e.Transfer(address indexed,address indexed,uint256)
without argument names)tokenIDs
([]int) — an array of token IDsaccounts
([]string) — an array of wallet addresses to listen ontopicHashes
([]string) — a hash of the event being listened to (e.g. ethers.id(“Transfer(address indexed from, address indexed to, uint256 amount)”))
For a full list of events from the various token types: ERC20, ERC721, or ERC1155, view here.
AddWebhookListener
Where this example listens to all mints of an ERC1155 collectible contract:
2. Remove a Webhook Listener
If you need to clean up your webhook listeners, you can submit requests to remove the listener based on listenerid
and projectId
:
Sequence Indexer RemoveWebhookListener
Method: with required*
fields
- Request: POST /rpc/Indexer/RemoveWebhookListener
- Content-Type: application/json
- Body (in JSON):
id*
(string) — the id of the listener returned fromAddWebhookListener
(i.e.response.listener.id
)projectId*
(string) — the Project ID the JWT Secret API key was obtained from
RemoveWebhookListener
Webhook Listener Response
Upon webhook listener response, an object is returned in the following structure- Response (in JSON):
uid
(string) — a deterministic hash value of the on-chain transaction logtype
(string), — the type of event (i.e.BLOCK_ADDED
)blockNumber
(i32) — the block number from the blockchain for when the event occuredblockHash
(string) — the hash of the block for the transactionparentBlockHash
(i32) — the hash of the parent blockcontractAddress
(string) — the contract address from where the event came fromcontractType
(string) — the type of contract (e.g.ERC20
,ERC721
,ERC1155
, etc.)txnHash
(string) — the transaction hash of the eventtxnIndex
(i32) — the index of the transaction in the blockchain blocktxnLogIndex
(string) — the log index in the transactionts
(date) — an ISO 8601 formatted date and time of the eventevent
(event) — the event data of the on-chain datatxnLogIndex
(string) — the log index in the transactionlogDataType
(string) — the type of log event (e.g.TOKEN_TRANSFER
)rawLog
(raw) — the raw transaction object
Example
Listen to a Specific Token ID for an ERC1155
If you want to get all mints and transfers of a specific token ID for an ERC1155On-chain Token Event Types
ERC20
- Transfer(address indexed from, address indexed to, uint256 value)
- Approval(address indexed owner, address indexed spender, uint256 value)
ERC721
- Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
- Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)
- ApprovalForAll(address indexed owner, address indexed operator, bool approved)
ERC1155
- TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value)
- TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values)
- ApprovalForAll(address indexed account, address indexed operator, bool approved)
- URI(string value, uint256 indexed id)
Custom Return Data Types Glossary
event (object)
Field | Type | Description |
---|---|---|
topicHash | string | a hash of the event being listened to (e.g. ethers.id(“Transfer(address indexed from, address indexed to, uint256 amount)“)) |
eventSig | string | the event signature of the on-chain event (e.g. “Transfer(address indexed from, address indexed to, uint256 amount)“) |
types | []string | an array of argument types from the event |
names | []string | an array of event argument names in plain text (note: if names are not included in initial webhook creation, will appear as: arg1, arg2, arg3, etc.) |
values | []string | an array of hex values corresponding to the argument names |
rawLog (object)
Field | Type | Description |
---|---|---|
data | string | data |
topics | []string | the topic event hashes emitted in the logs |