Mailer

Send emails from smart contracts with 1 line of code

You can use HAL to:

  • send emails to your users/clients from your smart contract

  • get notified about any event, transaction or contract' state change you care about

Use HAL as a mailer

If you need to send emails to your DAO members (e.g. "you need to vote on something"), clients (e.g. "the trade is completed") or users (e.g. you won the jackpot!") you could code something like this in your smart contract:

event SendEmail(string indexed to, string var1, int128[2] var2);

where "to" will be filled with the email address of the user you'd like to contact and var1 and var2 are 2 examples of specific values that you need to insert in the email template (depending on your business logic).

Be careful. Minimize parameters number and keep the use of strings to the minimum. Gas costs!

From HAL:

  • Create an EventsTrigger

  • Insert your smart contract's main net address

  • Select the SendEmail function

  • Don't add any filter

  • Active the Email action. In the To field, insert !to

  • In the subject insert "!var1 vote is coming!"

  • In the message insert "Just to notify that our !var2[0] vote is coming. We're voting for !var1. Please vote before the deadline, which occurs at block !var2[1]. Best. The DAO Governance Team"

Now it's time to play! When your smart contract will emit this:

to = "matthew_loves_DAOs@gmail.com" // you need to keep your users' emails somewhere;
var1 = "Board election" // vote name
var2[0] = 34; // DAO vote number
var2[1] = 9356917; // Block number when vote closes
emit SendEmail(to, var1, var2);

Matthew will receive the email and will meet the vote's deadline.

Get email notifications

Want to be notified when DEXs' trades occur, when you receive Ether or tokens, when new auctions open, when a gambling jackpot is higher than X, when Ether price is higher or lower than Y and much more?

You can create aTransactionsTrigger, ContractsTrigger orEventsTrigger depending on what you need and use the Email action. Any field (To, Subject or Message) supports templating variables. Not only basic variables (transactionHash, blockTime, etc) but also any parameter passed to the smart contract function (TransactionsTrigger), any part of the Events' payload (EventsTrigger) or any value returned by contracts' call/"state mutability: view" functions (ContractsTrigger).

To have insights about the list of available variables in the different cases, please see the Action section.

Want to get notified when more than 300 units of ZRX (0x) token are sold on IDEX?

  • Create a TransactionsTrigger (IDEX doesn't emit Events from the Trade function so we need to check the transactions)

  • In the To field, write 0x2a0c0DBEcC7E4D658f48E01e3fA353F44050c208 (IDEX address). Click "It's a contract" to enable advanced filtering. To know more about the Trade function parameters', just check out the contract's source code.

  • In the position 1 of the tradeAddressses array (called tokenSell in the source code), insert the address of the ZRX token (0xe41d2489571d322189246dafa5ebde1f4699f498)

  • In the position 1 of the tradeValues array (amountSell) insert the desidered amount (BiggerThan 300)

  • Create your custom email action

  • You're done!

Want to get notified about Ether price drops (Ether < 130$)? How about using using Uniswap DAI<->ETH market (1 DAI should be worth about 1$...)?

  • Create a ContractsTrigger and insert the 0x09cabec1ead1c0ba254b09efb3ee13841712be14 address (which is Uniswap exchange for single collateral DAI)

  • Select the getTokenToEthOutputPrice function

  • Insert 1 as input

  • getTokenToEthOutputPrice has only one returned value. Apply "SmallerThan 130" on that

  • Create your custom email action

  • You're done!