Implement maintenance using Chainlink Keepers to manage system tasks. Users cannot initiate all the smart contract actions necessary to keep a system up and running. Many application teams use centralized services for automation and maintenance tasks. se services are critical infrastructure components for many decentralized applications. Chainlink Keepers enables application development teams to outsource automated centralized tasks to a decentralized platform.
Chainlink Keepers is an off-chain infrastructure layer that interacts with smart contracts on the blockchain. Provides developers with access to secure and reliable off-chain smart contract automated computing services. Developers don’t need to run manual tasks, rely on centralized infrastructure services, or implement low-level protocol changes to automate chain events. y have the option to outsource this work to Chainlink Keepers.
Chainlink Keeper Use Cases
Most decentralized application teams don’t want to manage servers and try to avoid internal automation. Developers can use Chainlink Keepers as a decentralized off-chain computing layer to automate key smart contract functions and custom events. Handlers are similar to an out-of-chain service, Cron Job, or Autosys job that needs to run to maintain a look and feel of an application.
Below are several example problems that Chainlink Keepers can help solve. Instead of using a centralized server to manage your system, you can use the Chainlink Keeper infrastructure.
- Payment transactions based on new block information
- A liquidation needs to occur due to an under-collateralized loan
- A costly computational transaction needs to occur
- Execute a complex order on a decentralized exchange
- Reinvest performance in defi protocols
- Withdraw commissions every week
- and more
Chain Link Keepers allow for off-chain automation of many different types of events. possibilities are endless.
Decisions to consider for automation tasks
re are many points to consider when determining whether or not to host automation tasks for an application.
- Reliability is paramount for an application
- system must be easy to use.
- Performing all tasks in a chain becomes very expensive over time
- Taking tasks within the chain and moving them off the chain will reduce gas rates.
- Do you have a reliable and secure server to manage these services?
- Do the costs make sense?
- Is cross-chain management important?
How do Chainlink Keepers work?
Keepers design consists of three participants:
1. Create an UpKeep Compatible Smart Contract
- Maintenance compatible contracts are smart contracts that need help with maintenance tasks.
2. Add the contract to the registry
- Logging is a discovery solution for past participants to track work.
Read also Toucan Protocol (BCT) Token What is it, how to buy and price?
3. Guardians
- Guardians are the actors who execute the requested maintenance tasks.
- tasks that Chainlink Keeper performs can, most of the time, be completely off the chain
- n do the maintenance work
- blockchain continues to provide security. Only valid transactions can be processes
How to implement a Chainlink Keeper
Let’s see how to make your contract compliant by registering it on the Keeper network and watching the caregiver perform the tasks. To implement a maintenance interface, you need binding tokens to pay Keeper and ETH to pay for transaction costs. Order Kovan test tokens using this faucet link and this page for a list of ETH taps. Use your favorite exchange to get Mainnet tokens.
Keeper Compatible Smart Contract
Implement KeeperCompatibleInterface and two functions below to make your contract compatible.
- checkUpkeep function is called by the Keeper in every block (approximately every 15 seconds). Boolean return value determines whether the smart contract needs service. If the contract requires maintenance, the return bytes are passed to the performUpkeep function.
- perform maintenance role is the maintenance task that the contract wants service to be performed on. If checkUpkeep boolean returns true, the system calls the function performUpkeep
interface required for a contract manager to be compliant is on Github at the following Chainlink location:
Keeper Compatible Smart Contract Example
To get started, use the sample counter contract below. This contract implements the holder compatible interface and functions for the holder. We will use the gatekeeper infrastructure to monitor the blockchain and update the counter in the contract when the block.timestamp is divisible by 7.
First, compile and implement the contract on the Ethereum blockchain. All contracts must be verified with Etherscan for acceptance into the Chainlink maintenance network.
// SPDX-License-Identifier: MIT pragma solidity ^ 0.8.0; interface KeeperCompatibleInterface {/ ** * @notice checks if the contract requires work to be done. * @param checkData data passed to the contract when checking for Upkeep. * @return UpkeepNeeded boolean to indicate whether the keeper should call * performUpkeep or not. * @return performData bytes that the keeper should call performUpkeep with, * if upkeep is needed. * / function checkUpkeep (bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData); / ** * @notice Performs work on the contract. Executed by the keepers, via the registry. * @param performData is the data which was passed back from the checkData * simulation. * / function performUpkeep (byte calldata performData) external; } contract counterContract is KeeperCompatibleInterface {// counter variable uint public counter; // function to test your counter function increaseCounter () public {counter + = 1; } // used to view the current block.timestamp function timeStamp () public view returns (uint) {return block.timestamp; } // check to see if the block.timestamp is divisible by 7 // if true call the performUpkeep function function checkUpkeep (bytes calldata / * checkData * /) external override returns (bool upkeepNeeded, bytes memory / * performData * /) { upkeepNeeded = (block.timestamp% 7 == 0); } // if the block.timestamp is divisible by 7 increase the counter (function checkUpkeep above) // keeper will perform update function performUpkeep (bytes calldata / * performData * /) external override {counter = counter + 1; }}
Try it in Remix
Also read How to trade cryptocurrencies on Binance? Guide from 0 to 100
Sign up for the Keeper network
Second, register your contract on Keeper Network. Go to the Chain Link Guardians portal to register their supervised maintenance contract. Connect your wallet to the Chainlink website and select register new maintenance.
n fill out the request form so the Keeper environment knows which contract to monitor. information you provide will be publicly visible on the blockchain. Chainlink encrypts the email address information. Make sure you have link tokens to fund your maintenance.
After completing the form, press Register Maintenance and confirm the transaction in MetaMask. Chainlink Keeper requests are automatically approved and should be up and running in minutes.
Approve the MetaMask transaction to process the maintenance request. Make sure the environment is correct.
You will receive a confirmation once the transaction is complete.
Once the transaction is complete and the above window closes, you will be directed to the Chainlink Keepers app home page. On this page you can see your scheduled jobs and their details:
- Keeper job status
- Link balance
- Minimum link balance
- Date added to the system
- Gas limit
- Add funding request
- Cancel maintenance request
- Maintenance work history
- etc.
Check maintenance
Finally, after waiting 5-10 minutes, navigate to your contract and check if the counter has changed. contract instructed the holder to update the meter when a condition is met. If the counter changes, the janitor is doing his job.
Now go back to the Chainlink Keepers app web page. After refreshing the page, you can view the work history generated by the holder. Based on Kovan’s test data below, the holder charged .015686 links per executed transaction.
Pay maintenance and add funds
- Your Chainlink balance is reduced each time a Guardian executes its performUpkeep role
- No cost to check Maintenance calls
- If you want to automate the addition of funds, call the addfunds () function in the keeperRegistry contract
- Anyone (not just the maintenance owner) can call the addfunds () function
- To withdraw funds, first cancel the maintenance work and then withdraw the funds
Also read What is the best cryptocurrency exchange?
To ensure that Chainlink managers are compensated for their services, a minimum balance is expected on each maintenance. If your funds fall below the specified amount, maintenance will not be performed. If your balance runs out, you can press the Add Funds button on the Chainlink Keepers app web page to add Chainlink tokens to your work.
Cancel your maintenance job
If you want to cancel your maintenance work, press the cancel button on the Chainlink Keepers app web page. This will require you to sign a message to confirm the cancellation.
With Chainlink Keepers you can create a decentralized hybrid application. As systems have more permissions, less innovation will grow exponentially. Once the ecosystem is comfortable using Keepers, use will go mainstream.
Chainlink Keeper Best Practices
For information on best practices, visit the Chainlink Keeper Best Practices documentation. y review the design patterns, modifiers, and settings to use in your contract.
more