Created
August 11, 2021 04:47
-
-
Save camharris/e5b5305aa9c810da699ddf9b0f53b419 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=true&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.4.24; | |
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/ChainlinkClient.sol"; | |
contract AlarmClockSample is ChainlinkClient { | |
bool public alarmDone; | |
address private oracle; | |
bytes32 private jobId; | |
uint256 private fee; | |
constructor() public { | |
//setPublicChainlinkToken(); | |
// set the Oracle contract address | |
setChainlinkOracle(0x46cC5EbBe7DA04b45C0e40c061eD2beD20ca7755); | |
// set LINKToken contract address | |
setChainlinkToken(0x84b9b910527ad5c03a9ca831909e21e236ea7b06); | |
oracle = 0x46cC5EbBe7DA04b45C0e40c061eD2beD20ca7755; | |
jobId = "842e5f3cbcd34f76bf416d92b47ed416"; | |
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