Create Automation-Compatible Contracts

Learn how to make smart contracts that are compatible with Automation.

Automation compatible contracts

A contract is Automation-compatible when it follows a specified interface that allows the Chainlink Automation Network to determine if, when, and how the contract should be automated.

The interface you use will depend on the type of trigger you want to use:

You can learn more about these interfaces here.

Example Automation-compatible contract using custom logic trigger

Custom logic Automation compatible contracts must meet the following requirements:

  • Import AutomationCompatible.sol. You can refer to the Chainlink Contracts on GitHub to find the latest version.
  • Use the AutomationCompatibleInterface from the library to ensure your checkUpkeep and performUpkeep function definitions match the definitions expected by the Chainlink Automation Network.
  • Include a checkUpkeep function that contains the logic that will be executed offchain to see if performUpkeep should be executed. checkUpkeep can use onchain data and a specified checkData parameter to perform complex calculations offchain and then send the result to performUpkeep as performData.
  • Include a performUpkeep function that will be executed onchain when checkUpkeep returns true.

Use these elements to create a compatible contract that will automatically increment a counter after every updateInterval seconds. After you register the contract as an upkeep, the Chainlink Automation Network frequently simulates your checkUpkeep offchain to determine if the updateInterval time has passed since the last increment (timestamp). When checkUpkeep returns true, the Chainlink Automation Network calls performUpkeep onchain and increments the counter. This cycle repeats until the upkeep is cancelled or runs out of funding.

undefined

Compile and deploy your own Automation Counter onto a supported Testnet.

  1. In the Remix example, select the compile tab on the left and press the compile button. Make sure that your contract compiles without any errors. Note that the Warning messages in this example are acceptable and will not block the deployment.
  2. Select the Deploy tab and deploy the Counter smart contract in the injected web3 environment. When deploying the contract, specify the updateInterval value. For this example, set a short interval of 60. This is the interval at which the performUpkeep function will be called.
  3. After deployment is complete, copy the address of the deployed contract. This address is required to register your upkeep in the Automation UI. The example in this document uses custom logic automation.

To see more complex examples, go to the Quick Starts page.

Now register your upkeep.

Vyper example

You can find a KeepersConsumer example here. Read the apeworx-starter-kit README to learn how to run the example.

What's next

Get the latest Chainlink content straight to your inbox.