WebHooks for Blockchain-Events

favo
vechain.energy
Published in
2 min readOct 4, 2022

--

Connecting Web-Services with Blockchains can be quite a challenge.

For example an API requires data from a contract, which is possible by interacting with a Blockchain-Node. Another Web-Service requires a change of contract state which is done by posting a transaction to the network.

Talking back from the Blockchain to a Web-Service is more complicated because calling an API within a contract is impossible.

Thats where vechain.energy’s new WebHooks come into play. In its first iteration it connects contracts with Web-APIs using emitted contract events.

Event Listener

Contracts can emit events which can be read from external applications using Blockchain nodes.

With the event-api vechain.energy offers a simple API to access events like a database:

For example reading the last VTHO Transfers:

https://event.api.vechain.energy/main/0x0000000000000000000000000000456E65726779/Transfer%20(address%20indexed%20_from,%20address%20indexed%20_to,%20uint256%20_value)?offset=0&limit=3&noMeta=true

With our new WebHooks we actively listen to these events and bring them to your application.

Using the event signature from a contracts code, the event can be listened to:

Event Listener

The listener can be applied to a single, multiple or all contracts.

The Hook

If a new block arrives and an event is emitted the WebHook is executed.

It can be a simple request to any API, triggering an action. It can also send information from the transaction or event with the request:

WebHook-Definition

Use-Cases

NFT

Listen for NFT Transfers, Sales or Marketplace listings and automatically tweet about them.

Messaging

Trigger emails for specific actions with additional data from your backend. For example welcome a new user or send a notification.

Implement API Calls into contracts

Implement events that trigger your API which uses transaction-api to reply with off-chain-data.

Notes

This is the first iteration, future updates will implement the ability for filters and other triggers.

If you have questions or interested in it, please let us know in our discord.

And while we talk discord:

We are luring developers into Discord to share their learnings and have discussions about everything and nothing. Do you want to grow with us? Join and help building a lasting developer community:

https://bit.ly/energy-discord

--

--