# 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.

![](https://lh7-us.googleusercontent.com/EM1y8WJJ4g2-LzkDSGN7oZaM0Fyh4p-RZZL5eu_FDkQslfeRAPg3WfWyayuwl97tQBfHeADxzZJIf8JdgjJZOLYWJOt2uGek1krME3_0RvsMp2lxN01KxhFs8Ju0gQcjPIJq43dWgwUjUkGG1rtw5_4)

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.\
   ![](https://lh7-us.googleusercontent.com/Yca5JcTTE5iRY4Z0ulBq3O1Qff9ukKlOFq8CS0UNg7NX-tfY_Xa306FxHsECstzWFUEcr0pQUd7ThLDNwOMl1sZE2bVLOExqQN4Bg68sQZYoanMBe4S710CB_8kpowDl4R-vn-bar6cgyJOiGZGY3Hg)<br>
2. Now, submit the below Job Spec and press the “Create job” button.

![](https://lh7-us.googleusercontent.com/6jLAtPbhOYGbCCGOT3ix33xHi2F90VWBhSp6-3ZywIp6r2t6k6kkRUjfgPZs_gVmWc0LAyMWblUD7breViIcss3i9wnuRt5NDJSVtrFQvr_5w3lIKnTAp_pEJP9Wu19_qH4OjCmKVm5g5PPl3u4fAxc)\
\
**Job Spec:**<br>

<pre><code>type = "directrequest"
schemaVersion = 1
name = "Sample Request"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "&#x3C;<a data-footnote-ref href="#user-content-fn-1">Oracle Contract Address</a>>"
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&#x26;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
"""
</code></pre>

\
3\. Once the Job has been submitted successfully, copy the External Job ID and remove the hyphen(‘-’) from the job ID\
\
![](https://lh7-us.googleusercontent.com/GC_-MIXgswjPbhLgwZ4edt6Z4ZgFKBk9BgwqMDfc7hHWJSNnT4qR3eNpYaWu-55oSEjLk45QXZcQkRMzczGAHIqjL8ntJ_wVagnCtDA3OfmcJV0_XStXyg3TQHuHngPgJGpa-QfqVFogZX2cAyooBdI)\
\
\
CONSUMER CONTRACT

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;


import "@goplugin/contracts2_3/src/v0.8/PluginClient.sol";
import "@goplugin/contracts2_3/src/v0.8/ConfirmedOwner.sol";

/**
* THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY.
* THIS EXAMPLE USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/


contract APIConsumer is PluginClient, ConfirmedOwner {
using Plugin for Plugin.Request;


uint256 public volume;
bytes32 private jobId;
uint256 private fee;


event RequestVolume(bytes32 indexed requestId, uint256 volume);


/**
* @notice Initialize the pli token and target oracle
*
* Details:
* A. Pli Token for Mainnt: 0xff7412ea7c8445c46a8254dfb557ac1e48094391
* B. Oracle: [Copy paste the Oracle Contract Address, which you deployed as first step in this page] (Plugin DevRel)
* C. jobId: <job ID>
*
*/
constructor() ConfirmedOwner(msg.sender) {
setPluginToken(0xff7412ea7c8445c46a8254dfb557ac1e48094391);//Pli address as mentioned in ‘A’
setPluginOracle(<Copy paste the Oracle Contract Address>);//Oracle address
jobId = "<job ID>";//Job ID as stored in ‘C’ JOB SUBMISSION
fee = (0.001 * 1000000000000000000) / 10;
}


/**
* Create a Plugin request to retrieve API response, find the target
* data, then multiply by 1000000000000000000 (to remove decimal places from data).
*/
function requestVolumeData() public returns (bytes32 requestId) {
Plugin.Request memory req = buildPluginRequest(
jobId,
address(this),
this.fulfill.selector
);


// Set the URL to perform the GET request on
// req.add(
// "get",
// "<sample_api_link>/data/pricemultifull?fsyms=ETH&tsyms=USD"
// );
req.add(
"get",
"<sample_api_link>/data/price?fsym=XDC&tsyms=USDT"
);


// Multiply the result by 1000000000000000000 to remove decimals
int256 timesAmount = 10 ** 18;
req.addInt("times", timesAmount);


// Sends the request
return sendPluginRequest(req, fee);
}


/**
* Receive the response in the form of uint256
*/
function fulfill(
bytes32 _requestId,
uint256 _volume
) public recordPluginFulfillment(_requestId) {
emit RequestVolume(_requestId, _volume);
volume = _volume;
}


/**
* Allow withdraw of Link tokens from the contract
*/
function withdrawPli() public onlyOwner {
PliTokenInterface pli = PliTokenInterface(PluginTokenAddress());
require(
pli.transfer(msg.sender, pli.balanceOf(address(this))),
"Unable to transfer"
);
}
}
```

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.

\
![](https://lh7-us.googleusercontent.com/xxck-HEhi_Oa6WricUE9iAFJLfFHoNoutTJCVbJWCqpNWfWPltwRK0jzwy633-AaROIzmSSBqshRk0G82qpbOm2KF6md8PczDrakHZWeyT6FAwWjeLZ9Z1DndM7FWppQadkbdJrPb_itg2wlV9u6Rk8)\ <br>

[^1]: address received as a result of operator.sol deployment
