Set Conditions

Set Contract Event and Webhook Conditions.

The setConditions method let's you specify and assign either webhook or contract event conditions to the circuit. When the specified conditions are met, the Lit Action code will be executed.

Each condition has a maximum retry limit of 3 for encountered errors before logging an unmatched condition and continuing the Circuit. See Error Strict Mode and Logs & Error Handling for a more in depth view of how errors are handled in the SDK.

When invoking this method, you provide an array of conditions that you want to set. These conditions are called either at the specified interval set in ConditionLogic or monitored in real-time by the specified API endpoint and emitted contract events.

SetConditions is optional. You can run the Circuit without specifying conditions.

import { CHAIN_NAME } from "lit-listener-sdk";
import { BigNumber } from "ethers";

newCircuit.setConditions(
    [
        new ContractCondition(
              "0x6968105460f67c3bf751be7c15f92f5286fd0ce5", // contract address
              [
                {
                  "anonymous": false,
                  "inputs": [
                    {
                      "indexed": true,
                      "internalType": "address",
                      "name": "to",
                      "type": "address"
                    },
                    {
                      "indexed": false,
                      "internalType": "uint256",
                      "name": "value",
                      "type": "uint256"
                    }
                  ],
                  "name": "Transfer",
                  "type": "event"
                },
              ], // abi
              CHAIN_NAME.polygon, // chainId
              "https://your_provider_url_for_this_network", // provider URL
              "Transfer", // event name
               ["to", "value"], // event name args
               ["0x6968105460f67c3bf751be7c15f92f5286fd0ce5", 
               BigNumber.from("500000")], // expected value
              "===", // match operator
              async (emittedValue) => { console.log("Value Emmited by the contract event",         emittedValue); }, // onMatched function
              async (emittedValue) => { console.log("Value Emmited by the contract event",         emittedValue); }, // onUnMatched function
              (error: Error) => { console.log("Error:", error); } // onError function,
        ), 
        new WebhookCondition(
          "https://api.example.com", // baseUrl
          "/endpoint", // endpoint
          "path.to.value", // responsePath
          20, // expected value
          "===", // match operator
          "my-api-key", // apiKey
              async (emittedValue) => { console.log("Value Emmited by the webhook event",         emittedValue); }, // onMatched function
              async (emittedValue) => { console.log("Value Emmited by the webhook event",         emittedValue); }, // onUnMatched function
          (error: Error) => { console.log("Error:", error); } // onError function,
        )  
    ]
)

Webhook Condition Parameters:

Contract Event Condition Parameters:

Last updated