Create Your First Condition Based Job

This tutorial will guide you through the process of automating a smart contract function using TriggerX's condition-based trigger system. We'll cover everything from understanding the contract to deploying a condition-driven job that executes a smart contract function based on real-time data from an external API.

Understanding the Smart Contract

Contract Functionality:

The smart contract we'll use contains a function helloWorld that increments a stored value by a specified amount each time it’s called.

Open in Remix

Why Automate with TriggerX

Manually monitoring conditions (like ETH price or market activity) is inefficient and error-prone. TriggerX enables automated, real-time execution of smart contract functions based on predefined conditions, eliminating delay and increasing reliability.

Step-by-Step Guide to Creating an Event-Based Job

  1. Access the TriggerX App: Navigate to the TriggerX application and connect your wallet.

  2. 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 Condition-Based Trigger. This will set your job to execute a smart contract function only when a specific condition is met.

  2. Enter Job Title: Give your job a meaningful title

  3. Choose Network: Select OP Sepolia as the network where your contract is deployed.

  4. Set Timeframe: Set the duration for which the job should actively listen for events. For example, choose 1 day.

  5. Choose Recurrence: Indicate whether this job should be: Recurring (executed every time the event is emitted) One-Time (executed only once on the first event) Choose the desired option based on your automation needs.

  6. Enter Contract Address: Input the address of the contract whose function you want to call when the event is triggered: 0x6bd14b295B10821c53AB92613593786A623fa612

  7. ABI Handling:

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

    • If it’s not verified, manually input the ABI during this step.

  8. Select Function to Trigger: From the available functions in the contract, choose: helloWorld

  9. Define Function Arguments:

    Argument Type:

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

    • Dynamic: Fetch the value dynamically from an API or an IPFS-hosted script.

    For Static Argument: Enter the value directly. For example, to increment by 1 every time the event occurs, input 1.

    For Dynamic Argument: Provide the IPFS link to your script that dynamically fetches the value. (Templates and documentation are available in the TriggerX DevHub).

  10. Enter Source Type:

    You’ll now define the source from which the condition will be monitored.

    • Choose between:

      • API

      • WebSocket

      • Oracle (currently disabled, under development)

    For this tutorial, we’re selecting the API.

  11. Enter Source URL:

    Enter the API URL from which to fetch the condition data: For this example, we will use:

https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd
  1. Enter Condition Type:

    Choose from the following comparison options:

    • Equals To

    • Not Equal To

    • Less Than

    • Greater Than

    • In Range

    • Less Than or Equal To

    • Greater Than or Equal To

    We're using In Range.

  2. Define Limits:

    Set the range within which the condition should trigger the function:

    • Lower Limit: 2972

    • Upper Limit: 2976

    For this example, if the ETH price in USD is between 2972 and 2976, the helloWorld function will be triggered.

  3. Finalize and Create Job: Click the “Create Job” button. While the system calculates the necessary fees, enjoy a mini-game featuring a man collecting food. Once the fee estimation is complete, click “Next” to finalize your job creation.

Summary

You’ve now successfully set up a condition-based job on TriggerX! Whenever the ETH price falls within the defined range, TriggerX will automatically execute your helloWorld function, incrementing the value stored in your smart contract, hands-free!

For more advanced features, customization, and templates, check out the TriggerX DevHub.

Last updated