🏁 It's the end of an era. Hal will sunset its services on June 1st, 2024. Learn more

Manlio Poltronieri

Manlio Poltronieri

May 18, 2020

Connect Ethereum to your Apps: HAL meets Telegram


Some time ago you decided to see for yourself what was the fuss about that DeFi stuff everyone was talking about, and now you’re hooked. But staying on top of everything in this hectic world isn’t as easy as you wish it was — or is it?

Hal and Telegram

Some time ago you decided to see for yourself what was the fuss about that DeFi stuff everyone was talking about, and now you’re hooked. But staying on top of everything in this hectic world isn’t as easy as you wish it was — or is it?

HAL meets Telegram: a love story

So we figured it would be sweet to monitor what’s going on in the blockchain world using Telegram, right? Here’s how to do it, in two minutes, and without coding.
Let’s say you want to set up a trading strategy based on the exchange rate between KNC and DAI on Kyber. If you’re not familiar with it, Kyber is one of the most used liquidity protocols in the DeFi ecosystem, with more than 100 integrations and 950+ million dollars in volume registered since its launch.
Kyber Network
The metric we want to track is when the exchange rate between KNC and DAI grows beyond a certain value. Normally, you would track it using the getExpectedRate function, a view function that takes three parameters: the source token contract address, the destination token contract address, and the amount of source token expressed in wei. It also returns two values: the expected rate, and the slippage rate.
It’s all a bit abstract, so here is what it looks like on Etherscan using (one) KNC and DAI as source and destination respectively:
Get Expected Rate
What we want now is a trigger that tracks the expected rate for us, and texts us when it meets our requirements. Ready?
What we want now is a trigger that tracks the expected rate for us, and texts us when it meets our requirements. Ready?

Create a new “Watch a Contract” trigger

Head over to https://9000.hal.xyz/discover, and create a “Watch a Contract” trigger.

Configure your trigger

We need to provide the input data to getExpectedRate, similarly to what we did on Etherscan:
  1. In the “Contract Address” field, put the KNC Network Proxy Contract Address: 0x818e6fecd516ecc3849daf6845e3ec868087b755
  2. From the dropdown menu, select “getExpectedRate
  3. Fill in the addresses for the tokens we are tracking: these are 0xdd974d5c2e2928dea5f71b9825b8b646686bd200 for KNC and 0x6b175474e89094c44da98b954eedeac495271d0f for DAI.
  4. And finally, insert the amount of source token in wei, for example for 1 KNC you’d put 1000000000000000000.
So much for the “input” data to our function. Now let’s specify the actual filter: we only care about the expected rate here, which is the first of the two returned values. In this example we want our trigger to fire when the expected rate is greater than 0.629 DAI, so we set 629000000000000000 in the first “Return” field.

Connect Telegram

Now for the fun part, you’ll need to have (or create) a Telegram bot (if you haven’t done this before have a look at the doc here, it only takes a minute). Then you’ll need to provide your bot token, and the chat ID for where you want your bot to post the message. At last, you can craft your message using a number of customizable placeholders.
And that is all! Give your trigger a name, hit the “Create” button and relax — HAL will do the rest of the hard work for you.
Congratulations for creating your first integration using HAL and Telegram!

Where to go from here

There’s a lot more you might want to explore:
HAL.xyz

A ConsenSys company

Products

Resources