Trigger a configured Job
  • 22 Mar 2024
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

Trigger a configured Job

  • Dark
    Light
  • PDF

Article summary

How to trigger your job depends on the trigger type configured on your job.


Webhook or HTTP
In case of webhook:

  • Go to your app
  • Trigger the Silent Data [Oracle] job by doing a POST request to the endpoint visible on your job configuration
  • Consume the Silent Data [Oracle] job result in your smart contract


Smart Contract
In case of Smart Contract:

  • Go to your app
  • Trigger the Silent Data [Oracle] job by calling a Silent Data [Oracle] smart contract method
  • Consume the Silent Data [Oracle] job result in your smart contract

An example of a trigger Smart Contract for Silent Data [Oracle], see the following example:

//Example trigger smart contract generated in Silent Data [Oracle]
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

// Use openzeppelin library to improve contract security
import '@openzeppelin/contracts/access/Ownable.sol';

// Import the interface for the funding contract
interface IFundingContract {
  function emitSilentDataJobTrigger(string calldata jobId) external;
}

contract TriggerContract is Ownable(msg.sender) {
  IFundingContract public fundingContract;

  // Edit the funding contract address, callable by the contract deployer
  function setFundingContract(address _fundingContract) external onlyOwner {
    fundingContract = IFundingContract(_fundingContract);
  }

  // Implement logic to call the funding contract, to emit an event that triggers a job
  // Only configured allowed contracts will be able to trigger specific jobs
  function exampleMethod(string calldata jobId) external {
    require(address(fundingContract) != address(0), 'Funding contract not set');
    
    // Add logic for job triggering here

    fundingContract.emitSilentDataJobTrigger(jobId);
  }
}



Was this article helpful?