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.
- 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
You will need to use the following LINK token address, oracle address, and JobSpec ID in order to create the Chainlink request.
Ropsten
LINK Token address: 0x20fE562d797A42Dcb3399062AE9546cd06f63280
Oracle address: 0xc99B3D447826532722E41bc36e644ba3479E4365
JobID: 2ebb1c1a4b1e4229adac24ee0b5f784f
Rinkeby
LINK token address: 0x01BE23585060835E02B77ef475b0Cc51aA1e0709
Oracle address: 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e
JobID: 4fff47c3982b4babba6a7dd694c9b204
Kovan
LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
JobID: a7ab70d561d34eb49e9b1612fd2e044b
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:
}
until
Required
The timestamp for which the Chainlink node will wait to respond.
Solidity example
req.addUint("until", now + 5 minutes);
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 */
}