This document provides detailed information about each Chainlink service module and its related methods available in the Foundry Chainlink toolkit.
To use these Solidity scripts, import the necessary one into your project and interact with its functions as part of your smart contract development and testing workflow. Ensure that your environment is configured according to the README.
- Foundry Chainlink Toolkit Documentation
- Data Feeds Services
- VRF Service
- Automation Services
- Automation script: Automation.s.sol
- Register Upkeep
- Register Upkeep (Log Trigger)
- Register Upkeep (Time Based)
- Get Pending Request
- Cancel Request
- Get Registration Config (Keeper Registrar v1.2, v2.0)
- Get Registration Config (Keeper Registrar v2.1)
- Add Funds
- Pause Upkeep
- Unpause Upkeep
- Cancel Upkeep
- Set Upkeep Gas Limit
- Get Min Balance For Upkeep
- Get State
- Get Upkeep Transcoder Version
- Get Active Upkeep IDs
- Get Upkeep
- Withdraw Funds
- Transfer Upkeep Admin
- Accept Upkeep Admin
- Get Type And Version
- Automation script: Automation.s.sol
- Functions Services
Chainlink Data Feeds are decentralized oracles that provide reliable off-chain data to smart contracts on the blockchain. Using this service, developers can access the latest round answer and other relevant information from the Data Feeds, enabling them to fetch real-world data in their web3 projects.
Data Feeds script: DataFeed.s.sol
This section provides methods and functionalities designed to interact with the OffchainAggregator smart contract, which serves as the core component of Chainlink Data Feeds.
- Method: getLatestRoundData
- Description: Get the latest round data for a Data Feed
- Returns:
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
roundId
: Round ID of Data Feedanswer
: Latest round answer for a Data FeedstartedAt
: Timestamp of when the round startedupdatedAt
: Timestamp of when the round was updatedansweredInRound
: Round ID of when the round was answered
- Usage:
DataFeedScript.getLatestRoundData()
- Method: getRoundData
- Description: Get the round data for a Data Feed
- Arguments:
(uint80 roundId)
roundId
: Round ID of Data Feed
- Returns:
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
roundId
: Round ID of Data Feedanswer
: Latest round answer for a Data FeedstartedAt
: Timestamp of when the round startedupdatedAt
: Timestamp of when the round was updatedansweredInRound
: Round ID of when the round was answered
- Usage:
DataFeedScript.getRoundData(1)
- Method: getDecimals
- Description: Get the decimals for a Data Feed
- Returns:
decimals [uint8]
: Decimals for a Data Feed - Usage:
DataFeedScript.getDecimals()
- Method: getDescription
- Description: Get the description for a Data Feed
- Returns:
description [string]
: Description for a Data Feed - Usage:
DataFeedScript.getDescription()
- Method: getAggregatorVersion
- Description: Get the version for a Data Feed
- Returns:
version [uint256]
: Version for a Data Feed - Usage:
DataFeedScript.getAggregatorVersion()
ENS script: ENSFeedsResolver.s.sol
This section provides methods and functionalities designed to interact with the Chainlink ENS Resolver.
Note Chainlink ENS is exclusively available on the Ethereum mainnet.
- Method:
resolveAggregatorAddress
- Description: Resolve Data Feed address for a token pair using the Chainlink ENS Resolver
- Arguments:
(string memory baseTick, string memory quoteTick)
baseTick
: Base tick of the token pairquoteTick
: Quote tick of the token pair
- Returns:
aggregatorAddress [address]
: Data Feed address for a token pair - Usage:
ENSFeedResolverScript.resolveAggregatorAddress("ETH", "USD")
- Method:
resolveAggregatorAddressWithSubdomains
- Description: Resolve Data Feed address for a token pair using the Chainlink ENS Resolver with subdomains
- Arguments:
(string memory baseTick, string memory quoteTick)
baseTick
: Base tick of the token pair.quoteTick
: Quote tick of the token pair.
- Returns: (address proxyAggregatorAddress, address underlyingAggregatorAddress, address proposedAggregatorAddress)
proxyAggregatorAddress
: Proxy Data Feed address for a token pairunderlyingAggregatorAddress
: Underlying Data Feed address for a token pairproposedAggregatorAddress
: Proposed Data Feed address for a token pair
- Usage:
ENSFeedResolverScript.resolveAggregatorAddressWithSubdomains("ETH", "USD")
Chainlink VRF (Verifiable Random Function) service is a critical component provided by Chainlink that enables smart contracts on the blockchain to securely and transparently access cryptographically secure and unpredictable randomness.
VRF script: VRF.s.sol
This section provides methods and functionalities designed to interact with the VRFCoordinator smart contract, which serves as the intermediary between smart contracts on the blockchain and the VRF service.
- Method: createSubscription
- Description: Create a new subscription to the VRF service
- Returns:
subscriptionId [uint64]
: VRF Subscription ID - Usage:
VRFScript.createSubscription()
- Method: fundSubscription
- Description: Fund a subscription to the VRF service with LINK tokens
- Arguments:
(uint256 amountInJuels, uint64 subscriptionId)
amountInJuels
: Amount of LINK tokens to be sent (in Juels)subscriptionId
: VRF Subscription ID
- Usage:
VRFScript.fundSubscription(1000000000000000000, 1)
- Method: cancelSubscription
- Description: Cancel a subscription to the VRF service and receive the remaining balance
- Arguments:
(uint64 subscriptionId, address receivingAddress)
subscriptionId
: VRF Subscription IDreceivingAddress
: Address to receive the balance of the subscription
- Usage:
VRFScript.cancelSubscription(1, "0x0000000000000000000000000000000000000000")
- Method: addConsumer
- Description: Add a new consumer to an existing VRF subscription
- Arguments:
(uint64 subscriptionId, address consumerAddress)
subscriptionId
: VRF Subscription IDconsumerAddress
: Address of the consumer
- Usage:
VRFScript.addConsumer("0x0000000000000000000000000000000000000000", 1)
- Method: removeConsumer
- Description: Remove a consumer from an existing VRF subscription
- Arguments:
(uint64 subscriptionId, address consumerAddress)
subscriptionId
: VRF Subscription IDconsumerAddress
: Address of the consumer
- Usage:
VRFScript.removeConsumer("0x0000000000000000000000000000000000000000", 1)
- Method: getSubscriptionDetails
- Description: Get details of an existing VRF subscription
- Arguments:
(uint64 subscriptionId)
subscriptionId
: VRF Subscription ID
- Returns:
(uint96 balance, uint64 reqCount, address owner, address[] memory consumers)
balance
: LINK balance of the subscription in juelsreqCount
: Number of requests for the subscription, determines fee tierowner
: Owner of the subscriptionconsumers
: List of consumers of the subscription
- Usage:
VRFScript.getSubscriptionDetails(1)
- Method: requestRandomWords
- Description: Request random words from the VRF service
- Arguments:
(uint64 subscriptionId, bytes32 keyHash, uint16 minimumRequestConfirmations, uint32 callbackGasLimit, uint32 numWords)
subscriptionId
: VRF Subscription ID. Must be funded with the minimum subscription balance required for the selected keyHashkeyHash
: Key hash related to maxGasPrice of a VRF. Different keyHashes have different gas pricesminimumRequestConfirmations
: How many blocks you'd like the oracle to wait before responding to the requestcallbackGasLimit
: How much gas you allow for fulfillRandomWords callbacknumWords
: The number of random values you'd like to receive in fulfillRandomWords callback
- Usage:
VRFScript.requestRandomWords(1, "0x83250c5584ffa93feb6ee082981c5ebe484c865196750b39835ad4f13780435d", 10, 500000, 3)
- Method: isPendingRequestExists
- Description: Check if there is a pending request for an existing VRF subscription
- Arguments:
(uint64 subscriptionId)
subscriptionId
: VRF Subscription ID
- Returns:
isPendingRequestExists [bool]
: True if there is a pending request for the subscription - Usage:
VRFScript.isPendingRequestExists(1)
- Method: requestSubscriptionOwnerTransfer
- Description: Request to transfer ownership of a VRF subscription to a new owner
- Arguments:
(uint64 subscriptionId, address newOwnerAddress)
subscriptionId
: VRF Subscription IDnewOwnerAddress
: Address of the new subscription owner
- Usage:
VRFScript.requestSubscriptionOwnerTransfer(1, "0x0000000000000000000000000000000000000000")
- Method: acceptSubscriptionOwnerTransfer
- Description: Accept the transfer of ownership of a VRF subscription
- Arguments:
(uint64 subscriptionId)
subscriptionId
: VRF Subscription ID
- Usage:
VRFScript.acceptSubscriptionOwnerTransfer(1)
- Method: getRequestConfig
- Description: Get the configuration details of VRF Coordinator requests
- Returns:
(uint16 minimumRequestConfirmations, uint32 maxGasLimit, bytes32[] memory s_provingKeyHashes)
minimumRequestConfirmations
: Global min for request confirmationsmaxGasLimit
: Global max for request gas limits_provingKeyHashes
: List of registered key hashes
- Usage:
VRFScript.getRequestConfig()
- Method: getTypeAndVersion
- Description: Get the type and version details of VRF Coordinator
- Returns:
typeAndVersion [string memory]
: Type and Version of VRF Coordinator - Usage:
VRFScript.getTypeAndVersion()
Chainlink Automation service enables conditional execution of your smart contracts functions through a hyper-reliable and decentralized automation platform.
Automation script: Automation.s.sol
This section provides methods and functionalities designed to interact with the KeeperRegistry and KeeperRegistrar smart contracts. Supported versions of Keeper Registry are v1.2, v1.3, v2.0, and v2.1. Supported versions of Keeper Registrar are v1.2, v2.0, and v2.1.
- Method: registerUpkeep
- Description: Register an upkeep task for Chainlink Automation to perform on a specified contract
- Arguments:
(uint96 amountInJuels, string memory upkeepName, string memory email, address upkeepAddress, uint32 gasLimit, bytes memory checkData)
amountInJuels
: Amount of LINK in juels to fund the upkeepupkeepName
: Upkeep name to be registeredemail
: Email address of upkeep contact ownerupkeepAddress
: Upkeep contract address to perform task ongasLimit
: Limit of gas to provide the target contract when performing upkeepcheckData
: Data passed to the contract when checking upkeep
- Returns:
requestHash [bytes32]
: Hash of the registration request - Usage:
AutomationScript.registerUpkeep(1000000000000000000, "upkeep", "email", "0x0000000000000000000000000000000000000000", 500000, "0x")
- Method: registerUpkeep_logTrigger
- Description: Register an upkeep task for Chainlink Automation to perform on a specified contract with a log trigger
- Arguments:
(uint96 amountInJuels, string memory upkeepName, string memory email, address upkeepAddress, uint32 gasLimit, bytes memory checkData, bytes memory triggerConfig)
amountInJuels
: Amount of LINK in juels to fund the upkeepupkeepName
: Upkeep name to be registeredemail
: Email address of upkeep contact ownerupkeepAddress
: Upkeep contract address to perform task ongasLimit
: Limit of gas to provide the target contract when performing upkeepcheckData
: Data passed to the contract when checking upkeeptriggerConfig
: Encoded log trigger configuration, use Utils.getLogTriggerConfig method to generate
- Returns:
requestHash [bytes32]
: Hash of the registration request - Usage:
AutomationScript.registerUpkeep_logTrigger(1000000000000000000, "upkeep", "email", "0x0000000000000000000000000000000000000000", 500000, "0x", "0x")
- Method: registerUpkeep_timeBased
- Description: Register an upkeep task for Chainlink Automation to perform on a specified contract with a time based trigger
- Arguments:
(uint96 amountInJuels, string memory upkeepName, string memory email, address upkeepAddress, uint32 gasLimit, bytes memory checkData, address cronUpkeepFactoryAddress, bytes4 upkeepFunctionSelector, string calldata cronString)
amountInJuels
: Amount of LINK in juels to fund the upkeepupkeepName
: Upkeep name to be registeredemail
: Email address of upkeep contact ownerupkeepAddress
: Upkeep contract address to perform task ongasLimit
: Limit of gas to provide the target contract when performing upkeepcheckData
: Data passed to the contract when checking upkeepcronUpkeepFactoryAddress
: Address of CronUpkeepFactory contractupkeepFunctionSelector
: Function selector of the upkeep functioncronString
: Cron string with a schedule for performing upkeep
- Returns:
requestHash [bytes32]
: Hash of the registration request - Usage:
AutomationScript.registerUpkeep_timeBased(1000000000000000000, "upkeep", "email", "0x0000000000000000000000000000000000000000", 500000, "0x", "0xCccCCCCcccCCcCccccCC00000000000000000000", "0x00000000", "0 0 * * *")
- Method: getPendingRequest
- Description: Get information about a pending registration request for an upkeep task
- Arguments:
(bytes32 requestHash)
requestHash
: Hash of the registration request
- Returns:
(address admin, uint96 balance)
admin
: Address of the admin of the upkeep taskbalance
: LINK balance of the upkeep task in juels
- Usage:
AutomationScript.getPendingRequest("0x0000000000000000000000000000000000000000000000000000000000000000")
- Method: cancelRequest
- Description: Cancel a pending registration request for an upkeep task
- Arguments:
(bytes32 requestHash)
requestHash
: Hash of the registration request
- Usage:
AutomationScript.cancelRequest("0x0000000000000000000000000000000000000000000000000000000000000000")
- Method: getRegistrationConfig
- Description: Get the registration configuration for upkeep tasks from the Keeper Registrar
- Returns:
(AutomationUtils.AutoApproveType autoApproveType, uint32 autoApproveMaxAllowed, uint32 approvedCount, address keeperRegistry, uint256 minLINKJuels)
autoApproveType
: Setting for auto-approve registrationsautoApproveMaxAllowed
: Max number of registrations that can be auto approvedapprovedCount
: Number of approved registrationskeeperRegistry
: Keeper registry addressminLINKJuels
: Minimum LINK that new registrations should fund their upkeep with
- Usage:
AutomationScript.getRegistrationConfig()
- Method: getRegistrationConfig
- Description: Get the registration configuration for upkeep tasks from the Keeper Registrar
- Arguments:
(AutomationUtils.Trigger triggerType)
triggerType
: Trigger type of the upkeep task
- Returns:
(AutomationUtils.AutoApproveType autoApproveType, uint32 autoApproveMaxAllowed, uint32 approvedCount, address keeperRegistry, uint256 minLINKJuels)
autoApproveType
: Setting for auto-approve registrationsautoApproveMaxAllowed
: Max number of registrations that can be auto approvedapprovedCount
: Number of approved registrationskeeperRegistry
: Keeper registry addressminLINKJuels
: Minimum LINK that new registrations should fund their upkeep with
- Usage:
AutomationScript.getRegistrationConfig(AutomationUtils.Trigger.CONDITION)
- Method: addFunds
- Description: Add funds to an upkeep task
- Arguments:
(uint256 upkeepId, uint96 amountInJuels)
upkeepId
: Upkeep IDamountInJuels
: Amount of LINK in juels to fund the upkeep
- Usage:
AutomationScript.addFunds(1, 1000000000000000000)
- Method: pauseUpkeep
- Description: Pause an upkeep task
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Usage:
AutomationScript.pauseUpkeep(1)
- Method: unpauseUpkeep
- Description: Unpause an upkeep task
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Usage:
AutomationScript.unpauseUpkeep(1)
- Method: cancelUpkeep
- Description: Cancel an upkeep task
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Usage:
AutomationScript.cancelUpkeep(1)
- Method: setUpkeepGasLimit
- Description: Set the gas limit for an upkeep task
- Arguments:
(uint256 upkeepId, uint32 gasLimit)
upkeepId
: Upkeep IDgasLimit
: Limit of gas to provide the target contract when performing upkeep
- Usage:
AutomationScript.setUpkeepGasLimit(1, 500000)
- Method: getMinBalanceForUpkeep
- Description: Get the minimum required balance for upkeep from the Keeper Registry
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Returns:
minBalance [uint96]
: Minimum required balance for upkeep in juels - Usage:
AutomationScript.getMinBalanceForUpkeep(1)
- Method: getState
- Description: Get the state of an upkeep task
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Returns:
registryState [RegistryState memory]
: State of the upkeep task (combined state structure of different versions of Keeper Registry) - Usage:
AutomationScript.getState(1)
- Method: getUpkeepTranscoderVersion
- Description: Get the upkeep transcoder version from Keeper Registry
- Returns:
upkeepFormat [AutomationUtils.UpkeepFormat]
: Upkeep transcoder version - Usage:
AutomationScript.getUpkeepTranscoderVersion()
- Method: getActiveUpkeepIDs
- Description: Get the list of active upkeep IDs from Keeper Registry
- Arguments:
(uint256 startIndex, uint256 maxCount)
startIndex
: Start index of the list of active upkeep IDsmaxCount
: Max number of active upkeep IDs to return
- Returns:
upkeepIDs [uint256[] memory]
: List of active upkeep IDs - Usage:
AutomationScript.getActiveUpkeepIDs(0, 10)
- Method: getUpkeep
- Description: Get the details of an upkeep task
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Returns:
(address target, uint32 executeGas, bytes memory checkData, uint96 balance, address admin, uint64 maxValidBlocknumber, uint96 amountSpent, bool paused)
target
: Target contract address of the upkeep taskexecuteGas
: Gas limit for the upkeep taskcheckData
: Data passed to the contract when checking upkeepbalance
: LINK balance of the upkeep task in juelsadmin
: Address of the admin of the upkeep taskmaxValidBlocknumber
: Max valid block number for the upkeep taskamountSpent
: Amount spent on the upkeep taskpaused
: True if the upkeep task is paused
- Usage:
AutomationScript.getUpkeep(1)
- Method: withdrawFunds
- Description: Withdraw funds from an upkeep task
- Arguments:
(uint256 upkeepId, address receivingAddress)
upkeepId
: Upkeep IDreceivingAddress
: Address to receive the withdrawn LINK
- Usage:
AutomationScript.withdrawFunds(1, "0x0000000000000000000000000000000000000000")
- Method: transferUpkeepAdmin
- Description: Transfer the admin of an upkeep task
- Arguments:
(uint256 upkeepId, address proposedAdmin)
upkeepId
: Upkeep IDproposedAdmin
: Address of the new admin of the upkeep task
- Usage:
AutomationScript.transferUpkeepAdmin(1, "0x0000000000000000000000000000000000000000")
- Method: acceptUpkeepAdmin
- Description: Accept the transfer of admin of an upkeep task
- Arguments:
(uint256 upkeepId)
upkeepId
: Upkeep ID
- Usage:
AutomationScript.acceptUpkeepAdmin(1)
- Method: getTypeAndVersion
- Description: Get the type and version for Keeper Registry
- Returns:
typeAndVersion [string memory]
: Type and Version of Keeper Registry - Usage:
AutomationScript.getTypeAndVersion()
Chainlink Functions service provides your smart contracts access to trust-minimized compute infrastructure, allowing you to fetch data from APIs and perform custom computation.
Functions script: Functions.s.sol
This section provides methods and functionalities designed to interact with the Functions Router smart contract.
- Method: createSubscription
- Description: Create Functions subscription
- Returns:
subscriptionId [uint64]
: Functions Subscription ID - Usage:
FunctionsScript.createSubscription()
- Method: createSubscriptionWithConsumer
- Description: Create Functions subscription with consumer
- Arguments:
(address consumerAddress)
consumerAddress
: Address of Functions Consumer
- Returns:
subscriptionId [uint64]
: Functions Subscription ID - Usage:
FunctionsScript.createSubscriptionWithConsumer("0x0000000000000000000000000000000000000000")
- Method: fundSubscription
- Description: Fund Functions subscription
- Arguments:
(address linkTokenAddress, uint256 amountInJuels, uint64 subscriptionId)
linkTokenAddress
: Address of Link TokenamountInJuels
: Amount of LINK in Juels to fund SubscriptionsubscriptionId
: Subscription ID
- Usage:
FunctionsScript.fundSubscription("0x0000000000000000000000000000000000000000", 1000000000000000000, 1)
- Method: cancelSubscription
- Description: Cancel Functions subscription
- Arguments:
(uint64 subscriptionId, address receivingAddress)
subscriptionId
: Subscription IDreceivingAddress
: Address to receive the balance of Subscription
- Usage:
FunctionsScript.cancelSubscription(1, "0x0000000000000000000000000000000000000000")
- Method: getSubscriptionDetails
- Description: Get subscription details
- Arguments:
(uint64 subscriptionId)
subscriptionId
: Subscription ID
- Returns:
subscriptionDetails [IFunctionsSubscriptions.Subscription]
: Subscription details - Usage:
FunctionsScript.getSubscriptionDetails(1)
- Method: addConsumer
- Description: Add a new consumer to an existing Functions subscription
- Arguments:
(uint64 subscriptionId, address consumerAddress)
subscriptionId
: Subscription IDconsumerAddress
: Address of Functions Consumer
- Usage:
FunctionsScript.addConsumer(1, "0x0000000000000000000000000000000000000000")
- Method: removeConsumer
- Description: Remove a consumer from an existing Functions subscription
- Arguments:
(uint64 subscriptionId, address consumerAddress)
subscriptionId
: Subscription IDconsumerAddress
: Address of Functions Consumer
- Usage:
FunctionsScript.removeConsumer(1, "0x0000000000000000000000000000000000000000")
- Method: proposeSubscriptionOwnerTransfer
- Description: Propose subscription owner transfer
- Arguments:
(uint64 subscriptionId, address newOwner)
subscriptionId
: Subscription IDnewOwner
: Address of new owner of Subscription
- Usage:
FunctionsScript.proposeSubscriptionOwnerTransfer(1, "0x0000000000000000000000000000000000000000")
- Method: acceptSubscriptionOwnerTransfer
- Description: Accept subscription owner transfer
- Arguments:
(uint64 subscriptionId)
subscriptionId
: Subscription ID
- Usage:
FunctionsScript.acceptSubscriptionOwnerTransfer(1)
- Method: timeoutRequests
- Description: Timeout subscription requests
- Arguments:
(FunctionsResponse.Commitment[] memory commitments)
commitments
: Commitments to timeout
- Usage:
FunctionsScript.timeoutRequests(commitments)
- Method: estimateRequestCost
- Description: Estimate Functions request cost
- Arguments:
(string memory donId, uint64 subscriptionId, uint32 callbackGasLimit, uint256 gasPriceWei)
donId
: ID of the DON where Functions requests will be sentsubscriptionId
: Subscription IDcallbackGasLimit
: Callback gas limitgasPriceWei
: Gas price in Wei
- Returns:
estimatedCost [uint96]
: Estimated cost of Functions request - Usage:
FunctionsScript.estimateRequestCost("donId", 1, 500000, 100000000000)