Get Started with Chainlink Keepers

Automated execution comes to the smart contract world

Lajos Deme
Coinmonks
Published in
6 min readSep 7, 2021
Image from https://chain.link

I attended the Smart Contract Summit #1 last month (which was the greatest event of the year for me so far!) where there was a lot of discussion about Chainlink Keepers, a new solution provided by Chainlink.

According to their website, “Chainlink Keepers enables smart contracts to automate key functions and event-driven tasks in a highly reliable, decentralized, and cost-efficient manner.

In short, the process works the following way: you create a keeper compatible smart contract, register an upkeep job on the Chainlink Keepers web app, then Chainlink Keepers perform your upkeep jobs at the specified intervals without any further input from you. In this article, we will look at how to build a keeper compatible smart contract and register an upkeep job, and how the whole thing works behind the scenes.

Using Chainlink Keepers

So, how do we make our contract keeper compatible? The first step is to import the KeeperCompatibleInterface from Chainlink into our contract. I assume that you already have a development environment set up, and know how to import packages (if not just check one of the beginner Solidity tutorials out there).

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.7;

import "@chainlink/contracts/src/v0.6/interfaces/KeeperCompatibleInterface.sol";

This interface has two functions, checkUpkeep and performUpkeep. The first will be responsible for checking if the contract has any work that needs to be done. It takes a bytes parameter called checkData which will be passed to your contract, and because you set this value only once, when registering your upkeep, always the same value will be passed here. You can use this value in your logic to determine whether your contract needs an upkeep or not. It returns a bool called upkeepNeed which determines whether performUpkeep will be called or not, and a bytes that will be passed to performUpkeep.

function checkUpkeep(
bytes calldata checkData
)
external
returns (
bool upkeepNeeded,
bytes memory performData
);

--

--

Lajos Deme
Coinmonks

Founder of www.mercuryprotocol.io | We're building the world's data marketplace