A tutorial that teaches how to use Chainlink Data Feeds to access real-world data, such as asset prices, directly from your smart contracts on the Base testnet.
curl -L https://foundry.paradigm.xyz | bash
foundryup
, to install the latest (nightly) build of Foundryforge install
.
To install Chainlink smart contracts, run:
foundry.toml
file by appending the following line:
DataConsumerV3
. The code uses the AggregatorV3Interface
interface from the Chainlink contracts library to provide access to price feed data.
The smart contract passes an address to AggregatorV3Interface
. This address (0xcD2A119bD1F7DF95d706DE6F2057fDD45A0503E2
) corresponds to the ETH/USD
price feed on the Base Goerli network.
src/DataConsumerV3.sol
, and delete the src/Counter.sol
contract that was generated with the project. (you can also delete the test/Counter.t.sol
and script/Counter.s.sol
files).
To compile the new smart contract, run:
cast wallet import
command to import the private key of the wallet into Foundry’s securely encrypted keystore:
deployer
account in your Foundry project, run:
.env
file in the home directory of your project, and add the RPC URL for the Base Goerli testnet:
.env
file has been created, run the following command to load the environment variables in the current command line session:
forge create
command. The command requires you to specify the smart contract you want to deploy, an RPC URL of the network you want to deploy to, and the account you want to deploy with.
To deploy the DataConsumerV3
smart contract to the Base Goerli test network, run the following command:
cast
command-line tool that can be used to interact with the smart contract that was deployed and call the getLatestPrice()
function to fetch the latest price of ETH.
To call the getLatestPrice()
function of the smart contract, run:
ETH / USD
price in hexadecimal form.