Testing
How to test, if my oracle can communicate with plugin and start sharing the data
In your remix IDE open a new file and name it as PluginClient.sol and copy paste the code contents.
Override your oracle address & job id in below client contract and deploy it in remix by overriding PLI mainnet address like below (Line number 21 & 22) in the smart contract to be replaced with your oracle contract address & job-id from previous steps
1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.4.24;
3
import "https://github.com/GoPlugin/contracts/blob/main/src/v0.4/PluginClient.sol";
4
import "https://github.com/GoPlugin/contracts/blob/main/src/v0.4/vendor/Ownable.sol";
5
contract AlarmClockSample is PluginClient,Ownable {
6
using Plugin for Plugin.Request;
7
8
bool public alarmDone;
9
address private oracle;
10
bytes32 private jobId;
11
uint256 private fee;
12
13
/**
14
* Network: Mainnet
15
* Oracle: Plugin - 0xf180e56bb575806aefaf2a7616622a9fc180b51c
16
* Job ID: Plugin - bcbac9232272445294102fdd1ee97c98
17
* Fee: 0.1 PLI
18
*/
19
constructor(address _pli) public Ownable() {
20
setPluginToken(_pli);
21
oracle = 0xf180e56bb575806aefaf2a7616622a9fc180b51c;
22
jobId = "982105d690504c5e9ce374d040c08654";
23
fee = 0.1 * 10 ** 18; // 0.1 PLI
24
alarmDone = false;
25
}
26
27
/**
28
* Create a Plugin request to start an alarm and after
29
* the time in seconds is up, return throught the fulfillAlarm
30
* function
31
*/
32
function requestAlarmClock(uint256 durationInSeconds) public returns (bytes32 requestId)
33
{
34
Plugin.Request memory request = buildPluginRequest(jobId, address(this), this.fulfillAlarm.selector);
35
// This will return in 90 seconds
36
request.addUint("until", block.timestamp + durationInSeconds);
37
return sendPluginRequestTo(oracle, request, fee);
38
}
39
40
/**
41
* Receive the response in the form of uint256
42
*/
43
function fulfillAlarm(bytes32 _requestId, uint256 _volume) public recordPluginFulfillment(_requestId)
44
{
45
alarmDone = true;
46
}
47
function withdrawPli() public onlyOwner() {
48
PliTokenInterface pliToken = PliTokenInterface(pluginTokenAddress());
49
require(pliToken.transfer(msg.sender, pliToken.balanceOf(address(this))), "Unable to transfer");
50
}
51
}
Copied!
After deployment, you will receive a contract address- In this case here it is -> xdc3017a414bf657a42fc183143e90d378f05ff0004
Fund your contract address with PLI ( let’s say 1 PLI) before you trigger sleep task like below
Once you submit the “requestAlarm”, a job will be triggered in your PLUGIN Node like below.
After couple of seconds, you should see the job is getting completed successfully
Copy link