Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Last active November 19, 2020 02:53
Show Gist options
  • Save PatrickAlphaC/e71aab73726c5a2f99ee00c1a70cfef8 to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/e71aab73726c5a2f99ee00c1a70cfef8 to your computer and use it in GitHub Desktop.
/** This example code is designed to quickly deploy an example contract using Remix.
* If you have never used Remix, try our example walkthrough: https://docs.chain.link/docs/example-walkthrough
* You will need testnet ETH and LINK.
* - Kovan ETH faucet: https://faucet.kovan.network/
* - Kovan LINK faucet: https://kovan.chain.link/
*/
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract AlarmClockSample is ChainlinkClient {
bool public alarmDone;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Kovan
* Oracle: Chainlink - 0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b
* Job ID: Chainlink - 982105d690504c5d9ce374d040c08654
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b;
jobId = "982105d690504c5d9ce374d040c08654";
fee = 0.1 * 10 ** 18; // 0.1 LINK
alarmDone = false;
}
/**
* Create a Chainlink request to start an alarm and after
* the time in seconds is up, return throught the fulfillAlarm
* function
*/
function requestAlarmClock(uint256 durationInSeconds) public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfillAlarm.selector);
// This will return in 90 seconds
request.addUint("until", block.timestamp + durationInSeconds);
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfillAlarm(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId)
{
alarmDone = true;
}
/**
* Withdraw LINK from this contract
*
* NOTE: DO NOT USE THIS IN PRODUCTION AS IT CAN BE CALLED BY ANY ADDRESS.
* THIS IS PURELY FOR EXAMPLE PURPOSES ONLY.
*/
function withdrawLink() external {
LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());
require(linkToken.transfer(msg.sender, linkToken.balanceOf(address(this))), "Unable to transfer");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment