You can use Chainlink to trigger a smart contract at a specified time. Using this Chainlink, you will create a request with a timestamp for the node to call back to your desired function. You can include additional logic in that function to perform additional computation.
Steps For Using This Oracle
- Write and deploy your Chainlinked contract using the network details below
- Fund it with LINK (1 LINK is required per-request)
- Call your request method
Chainlink Network Details
You will need to use the following LINK token address, oracle address, and JobSpec ID in order to create the Chainlink request.
Rinkeby
LINK token address: 0x01BE23585060835E02B77ef475b0Cc51aA1e0709
Oracle address: 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e
JobID: 4fff47c3982b4babba6a7dd694c9b204
Kovan
LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
JobID: a7ab70d561d34eb49e9b1612fd2e044b
Create your Chainlinked contract
Import Chainlinked.sol
into your contract so you can inherit the Chainlinked
behavior.
pragma solidity ^0.4.24;
import "chainlink/contracts/ChainlinkClient.sol";
contract ChainlinkAlarmClock is ChainlinkClient {
uint256 oraclePayment;
constructor(uint256 _oraclePayment) public {
setPublicChainlinkToken();
oraclePayment = _oraclePayment;
}
// Additional functions here:
}
Tasks
Request Parameters
until
Required
The timestamp for which the Chainlink node will wait to respond.
now
keywordSolidity 0.7.0 deprecated the now keyword. For contracts ^0.7.0, you must use
block.timestamp
Solidity example
req.addUint("until", now + 5 minutes);
Chainlink Examples
This example shows how to create the request for the Chainlink node:
function delayStart
(
address _oracle,
bytes32 _jobId
)
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfill.selector);
req.addUint("until", now + 5 minutes);
sendChainlinkRequestTo(_oracle, req, oraclePayment);
}
This example shows the callback method:
function fulfill(bytes32 _requestId)
public
recordChainlinkFulfillment(_requestId)
{
/* additional computation here */
}
Updated 2 months ago