DEV Community

Cover image for Tutorial: Build an app that receives an email when ERC-20 transactions occurs
MESG
MESG

Posted on

Tutorial: Build an app that receives an email when ERC-20 transactions occurs

In this tutorial we'll cover how to recreate an ERC-20 to Email application using the MESG Framework, which will run and manage the application for you. Allowing the MESG Engine to run your application, it will also enable decentralization without any additional steps.

What do we want to build?

We want to listen to all transfer events from a specific smart contract and send an email for each one of them.

In order to do that, we will split this tutorial into two parts to create our application.

  1. The triggering of the process (the ERC-20 event we want to listen to)
  2. The task to execute (the email we want to send)

How do we build this?

We will use the MESG Orchestrator and will create a process file.

ERC-20 Transfer trigger

Let's create our process file.

key: erc20-notifications
steps:
  - type: trigger
    instance:
      src: https://github.com/mesg-foundation/service-ethereum-erc20
      env:
        - PROVIDER_ENDPOINT=$(env:PROVIDER_ENDPOINT)
        - CONTRACT_ADDRESS=0xdac17f958d2ee523a2206206994597c13d831ec7
    eventKey: transfer

Here, we create our first step of our process that is a trigger. We listen for all the events transfer of the service that is running with the environment variables:

PROVIDER_ENDPOINT : The address of the Ethereum node that will be injected during the compilation.|

CONTRACT_ADDRESS : The address of the ERC-20 to watch (USDT) 0xdac17f958d2ee523a2206206994597c13d831ec7

Send the email

Let's add the next task that will send an email each time our event is triggered. We will use the SendGrid service to send an email.

key: erc20-notifications
steps:
  ...
  - type: task
    instance:
      src: https://github.com/mesg-foundation/service-email-sendgrid
      env:
        - SENDGRID_API_KEY=$(env:SENDGRID_API_KEY)
    taskKey: send
    inputs:
      from: "test@erc20notification.com"
      to: "__YOUR_EMAIL_HERE__"
      subject: "New ERC20 transfer"
      text:
        key: transactionHash

We just added another step of type task that will use the service configured with the environmental variable SENDGRID_API_KEY that will be set during the deployment.

From this service, the task send will be called with a specific set of inputs:

  • from: A constant value for the sender of the email
  • to: The email you want to use to receive your notification
  • subject: A subject for your email
  • text: The text of your email.

The text input is an actual reference to the value transactionHash from our event. Every time a email will be sent, the value of the text will actually be the value of the transactionHash from the event.

Follow the whole tutorial

Top comments (0)