Skip to content

Commit

Permalink
start work on automation contract
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Oct 17, 2023
1 parent 5321ba7 commit 1f1046f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ yarn start
```

4. Fund the VRFConsumer contract with LINK. Visit the [LINK faucet](https://faucets.chain.link/)

### Example BG Project Exploration links

- https://jadenkore.medium.com/creating-a-dynamic-nft-that-updates-in-real-time-based-on-chain-data-3d989c04f137

- https://app.buidlguidl.com/build/NxKk0AQM5LBm2ks4aSZr

- https://github.com/danielkhoo/scaffold-eth/tree/buidl-guidl-dynamic-nft
46 changes: 46 additions & 0 deletions packages/hardhat/contracts/AutomationConsumer.sol
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();
}
}
}
16 changes: 12 additions & 4 deletions packages/nextjs/pages/automation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const AutomationPage: NextPage = () => {
<InformationSection
summary={
<>
Chainlink Automation allows you to call a smart contract function if a specific set of conditions are met.
The{" "}
Chainlink Automation calls a smart contract function if a specified set of criteria are met. The{" "}
<ExternalLink
href="https://docs.chain.link/chainlink-automation/job-scheduler"
text="time-based trigger"
Expand Down Expand Up @@ -42,11 +41,20 @@ const AutomationPage: NextPage = () => {
href="https://docs.chain.link/chainlink-automation/register-upkeep"
text="custom logic trigger"
/>{" "}
requires your target contract be compatible with <InlineCode text="AutomationCompatibleInterface" />
requires your target contract be compatible with{" "}
<ExternalLink
href="https://docs.chain.link/chainlink-automation/reference/automation-interfaces#automationcompatibleinterface"
text="AutomationCompatibleInterface"
/>{" "}
by overriding the <InlineCode text="checkUpkeep" /> and <InlineCode text="performUpkeep" /> functions
</>,
<>
The <ExternalLink href="https://docs.chain.link/chainlink-automation/log-trigger" text="log trigger" />{" "}
requires your target contract be compatible with <InlineCode text="AutomationCompatibleInterface" />
requires your target contract be compatible with{" "}
<ExternalLink
href="https://docs.chain.link/chainlink-automation/reference/automation-interfaces#ilogautomation"
text="IlogAutomation"
/>
</>,
]}
gettingStarted={[
Expand Down

0 comments on commit 1f1046f

Please sign in to comment.