Listener: Subscribe an internal service to any event

Overview

A Listener is a midpoint that listen for an event from a contract and makes an HTTP request based on the values from the event values.

As an example of a Listener, we will define a midpoint that sends Slack notification when a user borrows a token on Aave V2.

EVMEventEmittedSource:

  1. Listen for the deposit event to be emitted

  2. Extract the sender, recipient address and amount to be send to the MakeHttpRequestTask

MakeHttpRequestTask:

  1. Notify the user via Slack using a Slack webhook

Midpoint

$ npm install -g midpoint-cli

$ midpoint init blank my-listener

1 . EVMEventEmittedSource

$ midpoint add-source evmEventEmittedSource listener-source

We define the EVM Event Emitted source so that Midpoint can listen for the borrow event.

2. CallEvmFunction Task

$ midpoint add-task callEvmFunction get-erc20-name

We define the Call EVM Function task to retrieve the ERC20 name of the token that was borrowed.

3. MakeHttpRequest Task

$ midpoint add-task makeHttpRequest send-to-slack

We define the Make HTTP Request task to notify users via Slack message using the Slack Webhook.

To add WEB_HOOK_URL as a secret:

$ midpoint add-secret <slack webhook url> WEB_HOOK_URL

4. Define Path

We define our path file.

5. Publish Midpoint

$ midpoint publish

Last updated

Was this helpful?