NEW

Join us at SmartCon 2023—where Web3 gets real. Get your ticket.

Register a Custom Logic Upkeep

This guide explains how to register a custom logic Upkeep that uses a compatible contract. You can register it using the Chainlink Automation App or from within a contract that you deploy.

  1. Click the Register New Upkeep button Click Register New Upkeep

  2. Connect your wallet using the Connect Wallet choose a network. For a list of supported networks, see the Supported Blockchain Networks section. The Chainlink Automation App also lists the currently supported networks. Connect With Metamask

  3. Select the custom logic trigger

  4. Provide the address of your compatible contract You do not need to verify the contract on-chain, but it must be compatible with the AutomationCompatibleInterface contract.

  5. Complete the required details:

    • Upkeep name: This will be publicly visible in the Chainlink Automation app.

    • Gas limit: This is the maximum amount of gas that your transaction requires to execute on chain. This limit cannot exceed the performGasLimit value configured on the registry. Before the network executes your transaction on chain, it simulates the transaction. If the gas required to execute your transaction exceeds the gas limit that you specified, your transaction will not be confirmed. Developers also have the ability to update performGasLimit for an upkeep. Consider running your function on a testnet to see how much gas it uses before you select a gas limit. This can be changed afterwards.

    • Starting balance (LINK): Specify a LINK starting balance to fund your upkeep. See the LINK Token Contracts page to find the correct contract address and access faucets for testnet LINK. This field is required. You must have LINK before you can use the Chainlink Automation service.

    • Check data: This field is provided as an input for when your checkUpkeep function is simulated. Either leave this field blank or specify a hexadecimal value starting with 0x. To learn how to make flexible upkeeps using checkData, see the Flexible Upkeeps guide.

    • Your email address: This email address will be encrypted and is used to send you an email when your upkeep is underfunded.

  6. Click Register upkeep and confirm the transaction in MetaMask. Upkeep Registration Success Message

Your upkeeps will be displayed in your list of Active Upkeeps. You must monitor the balance of your upkeep. If the balance drops below the minimum balance, the Chainlink Automation Network will not perform the Upkeep. See Managing Upkeeps to learn how to manage your upkeeps.

Register an Upkeep using your own deployed contract

You can dynamically create and manage Upkeeps using your own smart contracts. The following example displays a smart contract that can create an Upkeep and determine the Upkeep ID. You can also program your Upkeep to check its own balance and fund itself by interacting with the registry.

Prerequisites

Find the following addresses for your network:

Optionally, you can fetch the LINK address and registrar address from the intended registry at run-time.

Mainnet and testnet use different versions of the Registry and Registrar interfaces.

  • Mainnet: Use the v1.x registrar and registry interfaces. See the Mainnet parameters section.
  • Testnet: Use the v2.0 registrar and registry interfaces. See the Testnet parameters section.

Code examples

Mainnet parameters

This uses v1.x registrar and registry interfaces.

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

// UpkeepIDConsumerExamplev1.sol imports functions from both ./AutomationRegistryInterface1_2.sol and
// ./interfaces/LinkTokenInterface.sol

import {AutomationRegistryInterface, State, Config} from "@chainlink/contracts/src/v0.8/interfaces/AutomationRegistryInterface1_2.sol";
import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */

interface KeeperRegistrarInterface {
    function register(
        string memory name,
        bytes calldata encryptedEmail,
        address upkeepContract,
        uint32 gasLimit,
        address adminAddress,
        bytes calldata checkData,
        uint96 amount,
        uint8 source,
        address sender
    ) external;
}

contract UpkeepIDConsumerExamplev1 {
    LinkTokenInterface public immutable i_link;
    address public immutable registrar;
    AutomationRegistryInterface public immutable i_registry;
    bytes4 registerSig = KeeperRegistrarInterface.register.selector;

    constructor(
        LinkTokenInterface _link,
        address _registrar,
        AutomationRegistryInterface _registry
    ) {
        i_link = _link;
        registrar = _registrar;
        i_registry = _registry;
    }

    function registerAndPredictID(
        string memory name,
        bytes calldata encryptedEmail,
        address upkeepContract,
        uint32 gasLimit,
        address adminAddress,
        bytes calldata checkData,
        uint96 amount,
        uint8 source
    ) public {
        (State memory state, , ) = i_registry.getState();
        uint256 oldNonce = state.nonce;
        bytes memory payload = abi.encode(
            name,
            encryptedEmail,
            upkeepContract,
            gasLimit,
            adminAddress,
            checkData,
            amount,
            source,
            address(this)
        );

        i_link.transferAndCall(
            registrar,
            amount,
            bytes.concat(registerSig, payload)
        );
        (state, , ) = i_registry.getState();
        uint256 newNonce = state.nonce;
        if (newNonce == oldNonce + 1) {
            uint256 upkeepID = uint256(
                keccak256(
                    abi.encodePacked(
                        blockhash(block.number - 1),
                        address(i_registry),
                        uint32(oldNonce)
                    )
                )
            );
            // DEV - Use the upkeepID however you see fit
        } else {
            revert("auto-approve disabled");
        }
    }
}

registerAndPredictID parameters

NameDescription
nameName of Upkeep
encryptedEmailNot in use in programmatic registration. Please specify with 0x
upkeepContractAddress of Keepers-compatible contract that will be automated
gasLimitThe maximum amount of gas that will be used to execute your function on-chain
adminAddressAddress for Upkeep administrator. Upkeep administrator can fund contract.
checkDataABI-encoded fixed and specified at Upkeep registration and used in every checkUpkeep. Can be empty (0x)
amountThe amount of LINK (in Wei) to fund your Upkeep. The minimum amount is 0.1 LINK. To fund 0.1 LINK please set this to 100000000000000000
sourceNot in use in programmatic registration. Please specify with 0.

Testnet parameters

This uses v2.0 registry and registrar interfaces.

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

// UpkeepIDConsumerExample.sol imports functions from both ./AutomationRegistryInterface2_0.sol and
// ./interfaces/LinkTokenInterface.sol

import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */

struct RegistrationParams {
    string name;
    bytes encryptedEmail;
    address upkeepContract;
    uint32 gasLimit;
    address adminAddress;
    bytes checkData;
    bytes offchainConfig;
    uint96 amount;
}

interface KeeperRegistrarInterface {
    function registerUpkeep(
        RegistrationParams calldata requestParams
    ) external returns (uint256);
}

contract UpkeepIDConsumerExample {
    LinkTokenInterface public immutable i_link;
    KeeperRegistrarInterface public immutable i_registrar;

    constructor(LinkTokenInterface link, KeeperRegistrarInterface registrar) {
        i_link = link;
        i_registrar = registrar;
    }

    function registerAndPredictID(RegistrationParams memory params) public {
        // LINK must be approved for transfer - this can be done every time or once
        // with an infinite approval
        i_link.approve(address(i_registrar), params.amount);
        uint256 upkeepID = i_registrar.registerUpkeep(params);
        if (upkeepID != 0) {
            // DEV - Use the upkeepID however you see fit
        } else {
            revert("auto-approve disabled");
        }
    }
}

registerAndPredictID parameters

NameDescription
nameName of Upkeep
encryptedEmailNot in use in programmatic registration. Please specify with 0x
upkeepContractAddress of Keepers-compatible contract that will be automated
gasLimitThe maximum amount of gas that will be used to execute your function on-chain
adminAddressAddress for Upkeep administrator. Upkeep administrator can fund contract.
checkDataABI-encoded fixed and specified at Upkeep registration and used in every checkUpkeep. Can be empty (0x)
offchainConfigNot in use. Please specify as 0x
amountThe amount of LINK (in Wei) to fund your Upkeep. The minimum amount is 0.1 LINK. To fund 0.1 LINK please set this to 100000000000000000

What's next

Stay updated on the latest Chainlink news