Below are the scripts available in the makefile-sandbox of the Foundry-Chainlink Toolkit.
All scripts are prefixed with fct-
to avoid makefile collisions when integrating with other projects.
Some scripts accept arguments that can be provided either through the command line (e.g. make target PARAM={value}
), in the .env
file, or interactively in the command line.
- Makefile Sandbox Scripts
- Installation
- Usage
- Project Structure
- Chainlink *
- External *
- Script *
- Src *
- Utility Scripts
- Chainlink Jobs Automatic Setup Scripts
- Chainlink Nodes Management Scripts
- Chainlink Jobs creation Scripts
- Create a Chainlink Job
- Create Chainlink Direct Request Job
- Create Chainlink Cron Job
- Create Chainlink Webhook Job
- Create Chainlink Keeper Job
- Create Chainlink Flux Job
- Create Chainlink OCR (bootstrap) Job
- Create Chainlink OCR (oracle) Job
- Create Chainlink Keeper Jobs
- Create Chainlink Flux Jobs
- Create Chainlink OCR Jobs
- Chainlink Jobs Helper Scripts
- Chainlink Smart Contracts Deployment Scripts
- ETH and Link Token Helper Scripts
- Direct Request Consumer Scripts
- Cron Consumer Scripts
- Keeper Consumer Scripts
- Registry Scripts
- Flux Aggregator Scripts
- Offchain Aggregator Scripts
Scripts for automating the initialization of the test environment and setting up Chainlink jobs will be described below.
To display autogenerated help with a brief description of the most commonly used scripts, run:
make fct-help
For a more detailed description of the available scripts, you can refer to SANDBOX.md.
make fct-init
This command automatically initializes the test environment, in particular, it makes clean spin-up of a Chainlink cluster of 5 Chainlink nodes.
Once Chainlink cluster is launched, a Chainlink nodes' Operator GUI will be available at:
- http://127.0.0.1:6711 - Chainlink node 1
- http://127.0.0.1:6722 - Chainlink node 2
- http://127.0.0.1:6733 - Chainlink node 3
- http://127.0.0.1:6744 - Chainlink node 4
- http://127.0.0.1:6755 - Chainlink node 5
For authorization, you must use the credentials specified in the chainlink_api_credentials.
You can also initialize the test environment manually by following these steps:
- Deploy Link Token contract
- Set
LINK_TOKEN_CONTRACT
in.env
- Spin up a Chainlink nodes cluster
- Fund Chainlink nodes with ETH
- Fund Chainlink nodes with Link tokens
Note
For ARM64 users. When starting a docker container, there will be warnings:
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
You can safely ignore these warnings, container will start normally.
make fct-setup-job
This command displays a list of available Chainlink jobs and sets up the selected one.
You can also set up a Chainlink job by calling the respective command.
make fct-setup-direct-request-job
This command automatically sets up a Direct Request job.
You can also set up a Direct Request job manually by following these steps:
- Deploy Oracle contract
- Deploy Consumer contract
- Fund Consumer contract with Link tokens
- Create Direct Request Job
- Request ETH price with Consumer contract, a corresponding job will be launched
- Get ETH price after completing a job
make fct-setup-cron-job
This command automatically sets up a Cron job.
You can also set up a Cron job manually by following these steps:
make fct-setup-webhook-job
This command automatically sets up a Webhook job.
You can also set up a Webhook job manually by following these steps:
make fct-setup-keeper-job
This command automatically sets up a Keeper job.
You can also set up a Keeper job manually by following these steps:
- Deploy Keeper Consumer contract
- Deploy Registry contract
- Create Keeper Jobs for Chainlink nodes in a cluster
- Register Chainlink nodes as keepers in a Registry contract
- Register Keeper Consumer as upkeep in a Registry contract
- Fund the latest upkeep in a Registry contract
- Get value of
counter
variable in a Keeper contract
make fct-setup-flux-job
This command automatically sets up a Flux job.
You can also set up a Flux job manually by following these steps:
- Deploy Flux Aggregator contract
- Fund Flux Aggregator contract with Link tokens
- Update Flux Aggregator available funds
- Set Flux Aggregator oracles
- Create Flux Jobs for the first 3 Chainlink nodes in a cluster
- Get the answer of the latest Flux round from the Flux Aggregator contract
make fct-setup-ocr-job
This command automatically sets up an OCR job.
You can also set up a OCR job manually by following these steps:
- Deploy Offchain Aggregator contract
- Set Offchain Aggregator payees
- Set Offchain Aggregator config
- Create OCR Job for a bootstrap Chainlink node (first in a cluster)
- Create OCR Jobs for Chainlink nodes in a cluster except the first one (bootstrap)
- Request new OCR round in the Offchain Aggregator contract (optional)
- Get the answer of the latest OCR round from the Offchain Aggregator contract
Note Manual set up of a Chainlink Job is recommended when utilizing a custom Consumer or Aggregator contract, or when a different job configuration is desired.
You can create a custom TOML file and use it to create a Chainlink Job instance through the Operator GUI or develop a custom script using the existing scripts provided by this toolkit.
Chainlink *
This directory contains configuration files, scripts and smart contracts source code.
Contracts *
- ChainlinkDirectRequestConsumer.sol - example consumer contract for Chainlink Direct Request Job
- ChainlinkCronConsumer.sol - example consumer contract for Chainlink Cron Job
- ChainlinkKeeperConsumer.sol - example consumer contract for Chainlink Keeper Job
- LinkToken.sol - flattened Link Token contract
Jobs *
- cron_job.toml - example configuration file for a Chainlink Cron job
- direct_request_job.toml - example configuration file for a Chainlink Direct Request job
- flux_job.toml - example configuration file for a Chainlink Flux job
- keeper_job.toml - example configuration file for a Chainlink Keeper job
- ocr_job.toml - example configuration file for a Chainlink OCR job
- ocr_job_bootstrap.toml - example configuration file for a Chainlink OCR (bootstrap) job
- webhook_job.toml - example configuration file for a Chainlink Webhook job
Note
More info on Chainlink v2 Jobs, their types and configuration can be found here: docs.chain.link/chainlink-nodes/oracle-jobs/jobs/.
You can change these configuration according to your requirements.
Setting *
- chainlink_api_credentials - Chainlink API credentials
- chainlink_password - Chainlink password
Note
More info on authentication can be found here github.com/smartcontractkit/chainlink/wiki/Authenticating-with-the-API.
You can specify any credentials there. Password provided must be 16 characters or more.
SQL *
- create_tables.sql - sql script to create tables related to Chainlink nodes in a Postgres DB
- chainlink_password - sql script to delete tables related to Chainlink nodes in a Postgres DB
Once Chainlink nodes are started, log directories will be created for each of them.
chainlink.env *
This file contains environment variables related to Chainlink node configuration. You can modify it according to your requirements.
More info on Chainlink environment variables can be found here: https://docs.chain.link/chainlink-nodes/v1/configuration.
Note
Subdirectories: jobs, settings and sql are used as shared folders for running Chainlink nodes and Postgres DB containers.
External *
This directory contains external libraries.
OCRHelper *
This Go library is based on https://github.com/smartcontractkit/chainlink-testing-framework integration tests and is used to prepare configuration parameters for Offchain Aggregator contract.
It has pre-built binaries for platforms: darwin/amd64(x86_64), darwin/arm64, linux/amd64(x86_64), linux/arm,linux/arm64.
Note
If you use another platform, in the root of the project please run:
make fct-build-ocr-helper
It will build the external library for your platform.
It requires Go (1.18 or higher) installed.
Script *
This directory contains Solidity Scripts to deploy and interact with Solidity smart contracts:
- Link Token
- Oracle
- Registry
- Flux and Offchain aggregators
- Chainlink Consumer contracts
- Helper Solidity Scripts
You can run these scripts with the command: forge script path/to/script [--args]
. Logs and artifacts dedicated to each script run, including a transaction hash and an address of a deployed smart contract, are stored in a corresponding subdirectory of the broadcast folder (created automatically).
More info on Foundry Solidity Scripting can be found here: https://book.getfoundry.sh/tutorials/solidity-scripting?highlight=script#solidity-scripting.
More info on forge script
can be found here: https://book.getfoundry.sh/reference/forge/forge-script.
Src *
Interfaces *
This directory contains interfaces to interact with Solidity contracts deployed using its pre-built artifacts. This is necessary in order to reduce dependence on a specific version of Solidity compiler.
Mocks *
This directory contains mock Solidity contracts used for testing purposes:
- MockAccessController.sol - mock contract used during deployment of Offchain Aggregator contract
- MockAggregatorValidator.sol - mock contract used during deployment of Flux Aggregator contract
- MockEthFeed.sol - mock contract used during deployment of Registry contract
- MockGasFeed.sol - mock contract used during deployment of Registry contract
make fct-help
This command displays autogenerated help with a brief description of the most commonly used scripts.
For a more detailed description of the scripts, you can refer to current file.
make fct-anvil
This command runs Anvil local Ethereum node with the following options:
- http endpoint: http://localhost:8545
- web socket: ws://localhost:8545
- chain ID: 1337
- block period: 10s
- mnemonic:
test test test test test test test test test test test junk
make fct-init
This command automatically initializes the test environment:
- Deploys the Link Token contract and writes its address to .env
- Spins up a Chainlink cluster
- Funds Chainlink nodes with ETH and Link tokens
make fct-setup-job
This command displays a list of available Chainlink jobs and sets up the selected one.
make fct-setup-direct-request-job
This command automatically sets up a Direct Request job:
- Deploys the Oracle and the Chainlink Direct Request Consumer contracts
- Funds the Chainlink Direct Request Consumer with Link tokens
- Creates a Direct Request job on a Chainlink node
- Makes request to the Oracle contract to update ETH price value
make fct-setup-cron-job
This command automatically sets up a Cron job:
- Deploys the Chainlink Cron Consumer contract
- Creates a Cron job on a Chainlink node
make fct-setup-webhook-job
This command automatically sets up a Webhook job:
- Creates a Webhook job on a Chainlink node
- Runs the most recently created Webhook job
make fct-setup-keeper-job
This command automatically sets up a Keeper job:
- Deploys the Registry and the Chainlink Keeper Consumer contracts
- Register the Chainlink Keeper Consumer in the Registry contract as an upkeep
- Sets Chainlink nodes as keepers in the Registry contract
- Creates a Keeper job on each Chainlink node in a Chainlink cluster
- Funds the latest registered upkeep in the Registry
make fct-setup-flux-job
This command automatically sets up a Flux job:
- Deploys the Flux Aggregator contract
- Funds the Flux Aggregator with Link tokens and updates its available funds
- Sets Chainlink nodes 1-3 as oracles in the Flux Aggregator contract
- Creates a Flux job on Chainlink nodes 1-3
make fct-setup-ocr-job
This command automatically sets up a OCR job:
- Deploys the Offchain Aggregator contract
- Sets Chainlink nodes 2-5 as payees in the Offchain Aggregator contract
- Sets OCR configuration generated by Chainlink nodes 2-5 in the Offchain Aggregator contract
- Creates an OCR (bootstrap) job on Chainlink node 1
- Creates an OCR (oracle) job on Chainlink nodes 2-5
make fct-run-nodes
This command spins up a cluster of 5 Chainlink nodes (necessary to run OCR jobs). It fetches images, creates/recreates and starts containers according to the docker-compose.yaml.
make fct-restart-nodes
This command performs a clean restart of a Chainlink cluster: stops and removes containers and network, deletes all related volumes and logs, and starts containers according to the docker-compose.yaml.
make fct-get-node-info
This command displays a list of available Chainlink node information and shows the selected one.
make fct-get-node-eth-keys
This command returns data related to Chainlink node's EVM Chain Accounts, e.g.:
- Account address (this is the address for a Chainlink node wallet)
- Link token balance
- ETH balance
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-get-node-ocr-keys
This command returns Chainlink node's OCR keys.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-get-node-p2p-keys
This command returns Chainlink node's P2P keys.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-get-node-address
This command returns Chainlink node's account address.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
Note
You also can find information on keys in the node Operator GUI under the Key Management configuration.
make fct-get-node-config
This command returns a Chainlink node configuration. The result contains comma-separated values, including:
Node address
On-chain signing address
Off-chain public key
Config public key
Peer ID
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-create-job
This command displays a list of available Chainlink jobs and creates the selected one.
make fct-create-direct-request-job
This command creates a Chainlink job according to direct_request_job.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDORACLE_ADDRESS
- Oracle contract address
make fct-create-cron-job
This command creates a Chainlink job according to cron_job.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDCRON_CONSUMER_ADDRESS
- Cron consumer contract address
make fct-create-webhook-job
This command creates a Chainlink job according to webhook_job.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-create-keeper-job
This command creates a Chainlink job according to keeper_job.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDREGISTRY_ADDRESS
- Registry contract address
Note
For the Chainlink Keeper Job it was noticed that Chainlink nodes require a current blockchain height to be approximately at least 100 blocks.
make fct-create-flux-job
This command creates a Chainlink job according to flux_job.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDFLUX_AGGREGATOR_ADDRESS
- Flux Aggregator contract address
make fct-create-ocr-bootstrap-job
This command creates a Chainlink job according to ocr_job_bootstrap.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDOFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract address
make fct-create-ocr-job
This command creates a Chainlink job according to ocr_job.toml.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDOFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract addressBOOTSTRAP_P2P_KEY
- P2P key for an OCR bootstrap Chainlink node
make fct-create-keeper-jobs
This command creates a Chainlink job for each Chainlink node in a cluster according to keeper_job.toml.
During the execution of the command, you will need to provide:
REGISTRY_ADDRESS
- Registry contract address
make fct-create-flux-jobs
This command creates a Chainlink job for the first 3 Chainlink nodes in a cluster according to flux_job.toml.
During the execution of the command, you will need to provide:
FLUX_AGGREGATOR_ADDRESS
- Flux Aggregator contract address
make fct-create-ocr-jobs
This command creates:
- Chainlink job for the first node (bootstrap) in a cluster according to ocr_job_bootstrap.toml.
- Chainlink jobs for each Chainlink node (oracles) except the first one (bootstrap) in a cluster according to ocr_job.toml.
During the execution of the command, you will need to provide:
OFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract address
Note
You can check list of created jobs and manage them in the node Operator GUI under the Jobs tab.
make fct-job-helper
This command displays a list of available helpers for Chainlink jobs and executes the selected one.
make fct-get-job-id
This command returns an ID of a Chainlink job whose name contains the specified contract address.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDCONTRACT_ADDRESS
- Contract address identifying a Chainlink job
make fct-get-external-job-id
This command returns an External ID of a Chainlink job whose name contains the specified contract address.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDCONTRACT_ADDRESS
- Contract address identifying a Chainlink job
make fct-get-last-webhook-job-id
This command returns a Job ID of the latest created Chainlink Webhook job.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-run-webhook-job
This command runs an existing Chainlink Webhook job.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDWEBHOOK_JOB_ID
- Webhook job ID
make fct-delete-job
This command deletes a Chainlink job with a specified job ID.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDJOB_ID
- Chainlink job ID
Note
You also can find information on jobs in the node Operator GUI under the Jobs tab.
Note
All contracts are deployed on behalf of the account specified in .env.
make fct-job-helper
This command displays a list of available Chainlink Smart Contracts and deploys the selected one.
make fct-deploy-link-token
This command deploys an instance of LinkToken.sol contract.
make fct-deploy-oracle
This command deploys an instance of Oracle.sol contract and whitelists Chainlink node address in the deployed contract.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDLINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-deploy-direct-request-consumer
This command deploys an instance of ChainlinkDirectRequestConsumer.sol contract.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-deploy-cron-consumer
This command deploys an instance of ChainlinkCronConsumer.sol contract.
make fct-deploy-keeper-consumer
This command deploys an instance of ChainlinkKeeperConsumer.sol contract.
make fct-deploy-registry
This command deploys an instance of KeeperRegistry1_3.sol contract.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-deploy-flux-aggregator
This command deploys an instance of FluxAggregator.sol contract.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-deploy-offchain-aggregator
This command deploys an instance of Chainlink OffchainAggregator.sol contract.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-funds-helper
This command displays a list of available helpers for ETH and Link Token and executes the selected one.
make fct-transfer-eth
With this command, you can send ETH to any specified recipient.
During the execution of the command, you will need to provide:
RECIPIENT
- Recipient address
make fct-transfer-eth-to-node
With this command, you can send ETH to any specified Chainlink node.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node ID
make fct-transfer-eth-to-nodes
With this command, you can send ETH to all Chainlink nodes in a cluster.
make fct-transfer-link
With this command, you can send Link tokens to any specified recipient.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract addressRECIPIENT
- Recipient address
make fct-transfer-link-to-node
With this command, you can send Link tokens to any specified Chainlink node.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDLINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-transfer-link-to-nodes
With this command, you can send Link tokens to all Chainlink nodes in a cluster.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-get-eth-balance
This command returns ETH balance of an account.
During the execution of the command, you will need to provide:
ACCOUNT
- Account
make fct-get-link-balance
This command returns Link Token balance of an account.
During the execution of the command, you will need to provide:
LINK_CONTRACT_ADDRESS
- Link Token contract addressACCOUNT
- Account
make fct-dr-consumer-request-eth-price
This command calls requestEthereumPrice
method of the Consumer contract, which asks the node to retrieve data specified in a Job configuration.
During the execution of the command, you will need to provide:
DIRECT_REQUEST_CONSUMER_ADDRESS
- Direct Request Consumer contract addressORACLE_ADDRESS
- Oracle contract addressDIRECT_REQUEST_EXTERNAL_JOB_ID
- Direct request External Job ID - you can get one with Chainlink Operator GUI on the Jobs tab
make fct-dr-consumer-request-eth-price-by-oracle
This command calls requestEthereumPrice
method of the Consumer contract, which asks the node to retrieve data specified in a Job configuration.
The respective Chainlink Direct Request job will be found using get-external-job-id script.
During the execution of the command, you will need to provide:
NODE_ID
- Chainlink node IDDIRECT_REQUEST_CONSUMER_ADDRESS
- Consumer contract addressORACLE_ADDRESS
- Oracle contract address
make fct-dr-consumer-get-eth-price
This command returns current value of currentPrice
variable specified in the Direct Request Consumer contract state.
During the execution of the command, you will need to provide:
DIRECT_REQUEST_CONSUMER_ADDRESS
- Direct Request Consumer contract address
make fct-cron-consumer-get-eth-price
This command returns current value of currentPrice
variable specified in the Cron Consumer contract state.
During the execution of the command, you will need to provide:
CRON_CONSUMER_ADDRESS
- Cron Consumer contract address
make fct-keeper-consumer-get-counter
This command returns the latest value of the counter
variable stored in the Keeper Consumer contract. This variable reflects the number of times the keepers performed the Keeper job.
During the execution of the command, you will need to provide:
KEEPER_CONSUMER_ADDRESS
- Keeper Consumer contract address
make fct-registry-register-upkeep
This command registers Keeper Consumer in the Registry contract as upkeep.
During the execution of the command, you will need to provide:
REGISTRY_ADDRESS
- Registry contract addressKEEPER_CONSUMER_ADDRESS
- Keeper Consumer contract address
make fct-registry-set-keepers
This command sets Chainlink nodes in the cluster as keepers in the Registry contract.
During the execution of the command, you will need to provide:
REGISTRY_ADDRESS
- Registry contract addressKEEPER_CONSUMER_ADDRESS
- Keeper Consumer contract address
make fct-registry-fund-latest-upkeep
This command funds the most recent upkeep in the Registry contract.
During the execution of the command, you will need to provide:
REGISTRY_ADDRESS
- Registry contract addressLINK_CONTRACT_ADDRESS
- Link Token contract address
make fct-flux-update-available-funds
This command recalculate the amount of LINK available for payouts in the Flux Aggregator contract.
During the execution of the command, you will need to provide:
FLUX_AGGREGATOR_ADDRESS
- Flux Aggregator contract address
make fct-flux-set-oracles
This command adds new oracles as well as updates the round related parameters in the Flux Aggregator contract.
During the execution of the command, you will need to provide:
FLUX_AGGREGATOR_ADDRESS
- Flux Aggregator contract address
make fct-flux-get-oracles
This command returns an array of addresses containing the oracles of the Flux Aggregator contract.
During the execution of the command, you will need to provide:
FLUX_AGGREGATOR_ADDRESS
- Flux Aggregator contract address
make fct-flux-get-latest-answer
This command returns the answer of the latest Flux round.
During the execution of the command, you will need to provide:
FLUX_AGGREGATOR_ADDRESS
- Flux Aggregator contract address
make fct-ocr-set-payees
This command sets Chainlink nodes 2-5 as payees
in the Offchain Aggregator contract.
During the execution of the command, you will need to provide:
OFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract address
make fct-ocr-set-config
This command sets OCR configuration in the Offchain Aggregator contract.
During the execution of the command, you will need to provide:
OFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract address
Note
This package uses external Go library OCRHelper to prepare an OCR configuration.
make fct-ocr-request-new-round
This command requests new OCR round immediately.
During the execution of the command, you will need to provide:
OFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract address
make fct-ocr-get-latest-answer
This command returns the answer of the latest OCR round.
During the execution of the command, you will need to provide:
OFFCHAIN_AGGREGATOR_ADDRESS
- Offchain Aggregator contract address