Steps to Setup Direct Request Job

ORACLE CONTRACT:

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
import "@goplugin/contracts2_3/src/v0.7/Operator.sol";

While deploying this contract, need to give the “PLI” as “0xFf7412Ea7C8445C46a8254dFB557Ac1E48094391” for Mainnet and for “Owner”, the wallet address from which you are going to deploy.

Once the contract is deployed, note down the Oracle contract address. Node Fulfillment:

In the deployed Oracle click on the ‘setAuthorizedSenders’ button and pass on the node address in array format e.g(["<Node_address>"], replace ‘xdc’ to ‘0x’ in the node address) and click on the ‘transact’.

JOB SUBMISSION:

  1. In the Jobs Section, click on the “New Job” button.

  2. Now, submit the below Job Spec and press the “Create job” button.

Job Spec:

type = "directrequest"
schemaVersion = 1
name = "Sample Request"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "<Oracle Contract Address>"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"]
 
decode_cbor [type="cborparse" data="$(decode_log.data)"]
 
fetch [type=http method=GET url="https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?symbol=XDC&convert=USDT" allowUnrestrictedNetworkAccess="true"];
parse [type="jsonparse" path="USDT" data="$(fetch)"]
 
multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
 
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"]
 
encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ]
 
submit_tx [type="ethtx" to="Oracle Contract Address" data="$(encode_tx)"] //paste the Oracle Address which you deployed in ‘to’ field
 
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""

3. Once the Job has been submitted successfully, copy the External Job ID and remove the hyphen(‘-’) from the job ID CONSUMER CONTRACT

Once the contract is deployed, fund the contract with 0.1 PLI and click on ‘requestVolumeData’ & wait for few minutes and then click on ‘volume’ to get the XDC-USDT value.

Last updated