How to Automate Your Smart Contract Executions Using Gelato

Integrating with Gelato Automate

brandon.cs
Gelato Network
4 min readAug 9, 2021

--

If you’ve ever written a smart contract, you would know that it is impossible to have a smart contract execute a certain function on its own under a specified condition (e.g. make a sell order when the price of Ethereum moons).

To achieve this you’d have to build your own bot which monitors on-chain activities and then have it send transactions. But building a bot like this requires a lot of work and developer resources that can instead be allocated to optimizing your smart contract or finally leaving your shadowy basement. Aside from that, you’d have to run your bot on a server and monitor it daily… sounds fun right? (Not.)

So sit back and let Gelato do the work for you, so you can prioritize building awesome smart contracts without worrying about becoming the central point of failure.

Starting Off

Let’s say you already have a smart contract deployed and you want Gelato to call it at a certain time. All you need to do is to deploy a resolver contract which will tell Gelato.

“Hey call this function here at every hour”

Here’s an example of the function buy()which I want Gelato to call. This function buys ETH through Uniswap V2.

Below is an example of a resolver contract, checker() returns true when it has been at least an hour past lastBought. This prompts Gelato to call the buy() function mentioned above.

Gelato calls this checker() off-chain at every block. If canExec returns true, executors will send a transaction with execPayload.

To get more information on how to write a resolver contract, take a look at the link below:

https://docs.gelato.network/developer-services/automate/guides/writing-a-resolver/smart-contract-resolver

Creating A Task

Once you have your resolver contract deployed, you’re already halfway done! Now you would need to submit a task. Gelato makes submitting tasks super easy with the Gelato Automate UI.

1. Visit the Gelato Automate webpage

Here you can see your current tasks.

2. Fill in your execution address

  • Fill in the smart contract address containing the function you want Gelato to call.
  • Select the function to be automated
  • Select “Dynamic inputs via Resolver”

3. Fill in the resolver address

  • Fill in the address of your resolver deployed previously.
  • Select the function gelato should call to check if the task should be executed.

4. Deposit Funds

  • Choose pay with “Gelato Balance”
  • Deposit some funds which will be used to pay executors for executing your transactions.

5. Name your task

6. Create Task

You will then be redirected to your task page.

Here you can find details of your task.

All the Gelato executions will also appear here.

All Done!

Gelato will now monitor your smart contract and execute when your specified conditions are met. Here are the contract addresses for each supported network, so you can jump right in and get started!

About Gelato Network

Gelato is Web3’s decentralized backend empowering builders to create augmented smart contracts that are automated, gasless & off-chain aware.

Leading Web3 projects rely on Gelato to power the execution of millions of transactions across DeFi, NFT and Gaming.

Connect with us

Twitter | Telegram | Discord

--

--