Create Your First Time Based Job

In this tutorial, you'll learn how to automate a smart contract function using TriggerX's time-based trigger. We'll walk through each step, from understanding the contract to setting up the job on the TriggerX platform.

Understanding the Smart Contract

Contract Functionality:

The smart contract we'll use has a function named helloWorld that increments a stored value each time it's called. This function accepts a single argument: the amount by which to increment the value.

Open in Remix

Why Automate with TriggerX:

Manually calling the helloWorld function at regular intervals can be tedious and error-prone. TriggerX allows you to automate this process, ensuring the function is called consistently based on a predefined schedule.

Step-by-Step Guide to Creating a Time-Based Job

  1. Access the TriggerX App:

Navigate to the TriggerX application and connect your wallet.

  1. Navigate to 'Create Job':

On the home page, click on the "Start Building" button. By default, this opens the custom job creation page.

  1. Select Trigger Type:

Choose Time-Based Trigger to schedule the function execution at regular intervals.

  1. Choose Network:

Select OP Sepolia as the network where your contract is deployed.

  1. Set Timeframe and Interval:

  • Timeframe: Set the duration for which the job should run. For this example, choose 1 day.

  • Interval: Specify how often the function should be called. Set this to every 1 minute.

  1. Enter Contract Address:

Input the address of your deployed contract:

0x6bd14b295B10821c53AB92613593786A623fa612
  1. ABI Handling:

  • If your contract is verified on the blockchain explorer, TriggerX will automatically fetch the ABI.

  • If it's not verified, you'll need to input the ABI during this step manually.

  1. Select Function to Trigger: From the list of available functions, choose helloWorld.

  2. Define Function Arguments:

  • Argument Type:

    • Static: Provide a fixed value that will be used every time the function is called.

    • Dynamic: Fetch the argument value dynamically, such as from an API or a script stored on IPFS.

  • For Static Argument:

    Enter the value directly in the provided field. For example, to increment by 1 each time, input 1.

  • For Dynamic Argument:

    Provide the IPFS link to the script that retrieves the desired value. You can find templates and guidelines for such scripts in the TriggerX documentation.

  1. Finalize and Create Job:

  • Click on the "Create Job" button.

  • While the system calculates the necessary fees, enjoy a mini-game featuring a man collecting food.

  • Once the fee calculation is complete, click "Next" to finalize the job creation.

Create Custom job

Summary

By following these steps, you've successfully set up a time-based automation job on TriggerX. This job will call the helloWorld function of your smart contract every minute for a day, incrementing the stored value as specified.

For more advanced configurations and examples, refer to the TriggerX DevHub.

Last updated