generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5321ba7
commit 1f1046f
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.7; | ||
|
||
import "@chainlink/contracts/src/v0.8/automation/AutomationCompatible.sol"; | ||
|
||
// Errors | ||
error AutomationConsumer__UpkeepNotNeeded(); | ||
|
||
/** | ||
* | ||
*/ | ||
contract AutomationConsumer is AutomationCompatibleInterface { | ||
// State variables | ||
|
||
/** Chainlink Keeper nodes call checkUpkeep to see if upkeepNeeded is true | ||
* | ||
* https://docs.chain.link/chainlink-automation/compatible-contracts#checkupkeep-function | ||
*/ | ||
function checkUpkeep( | ||
bytes memory /* checkData */ | ||
) | ||
public | ||
pure | ||
override | ||
returns (bool upkeepNeeded, bytes memory /* performData */) | ||
{ | ||
upkeepNeeded = true; | ||
} | ||
|
||
/** | ||
* @dev Once `checkUpkeep` returns true, this function triggers | ||
* the Chainlink VRF node being called to generate a random number | ||
* | ||
* @dev then the `fullfillRandomWords` function is automatically called once the Chainlink VRF node | ||
* returns the random number because of this contract inherting from `VRFConsumerBaseV2` | ||
* | ||
* @dev https://docs.chain.link/chainlink-automation/compatible-contracts#performupkeep-function | ||
*/ | ||
function performUpkeep(bytes calldata /* performData */) external override { | ||
// best practice to revalidate the upkeepNeeded | ||
(bool upkeepNeeded, ) = checkUpkeep(bytes("0x")); | ||
if (!upkeepNeeded) { | ||
revert AutomationConsumer__UpkeepNotNeeded(); | ||
} | ||
} | ||
} |
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