- Mainly composed of
ChainlinkClient
. - Initialize
VRFCoordinatorV2Interface
. - Use
requestRandomWords
function to initiate the request. - Obtain and utilize the random number in the callback function
fulfillRandomWords
.
Main functionalities:
- Off-chain data request: The contract utilizes functionalities provided by Chainlink to fetch weather data from an external API. By calling the
requestCurrentWeather
function, the contract sends a request to the specified API and retrieves the current weather temperature via Chainlink service. - Off-chain data processing: The contract receives off-chain data responses from Chainlink and passes the weather temperature information from the response as a parameter to the
changeERTStatus
function of the Models contract, thereby updating the NFT status based on external weather temperature. - Access control: The contract implements access control functionality, allowing only authorized users to call functions such as
requestCurrentWeather
to initiate weather data requests and other privileged operations. - Event notification: The contract defines multiple events, including requesting weather data, receiving weather data responses, etc., for monitoring the contract's state changes and operation status.
- Security measures: The contract adopts security measures such as access control and event notification to enhance contract security and stability, preventing unauthorized operations and handling exceptional situations.
- Off-chain service configuration: The contract requires configuration of off-chain service parameters during deployment, including off-chain API addresses, Chainlink node addresses, etc.
- Construct request using
buildChainlinkRequest
. - Send GET request to node using
sendChainlinkRequestTo
. - Node callback triggers
fulfillWeather
function, returning weather temperature. - Call
changeERTStatus
function of Models contract to alter temperature.
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
Try running some of the following tasks:
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.js