- Run foundry local node on a saperate terminal using
anvil
command. - Create a
.env
file and specify these environment variables inside it.
# anvil
# This is a RPC_URl of local node (Anvil) provided by foundry.
ANVIL_RPC_URL=http://127.0.0.1:8545
# This is a private key of the first account.
ANVIL_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- Create an alias for the
ANVIL_RPC_URL
inside thefoundry.toml
file. This will help us later in the command. Make sure to add[rpc_endpoints]
above it.
[rpc_endpoints]
anvil = "${ANVIL_RPC_URL}"
- Compile the contracts using
forge build
command (fix any issues you face). - Load the
.env
file variables using the commandsource .env
- FundMe contract require the
price-feed
address in the constructor parameter, so for the local development we need to deploy the mocks to get theprice-feed
address. Deploy the mocks using command;
forge create MockV3Aggregator --rpc-url anvil --private-key $ANVIL_PRIVATE_KEY
- Now we can deploy the FundMe contract and pass the address of mock contract (you can copy the address from terminal);
forge create FundMe --constructor-args <address-of-mock-contract> --rpc-url anvil --private-key $ANVIL_PRIVATE_KEY
Note: We only have 1 smart contract due to that we only specify the name of it (FundMe) in the command but incase you have multiple contract inside the same file or in different files then you need to specify the full path of smart contract i.e in our case src/FundMe.sol:FundMe
- Specify the
SEPOLIA_RPC_URL
,PRIVATE_KEY
andETHERSCAN_API_KEY
inside the.env
file.
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/...
PRIVATE_KEY=...
ETHERSCAN_API_KEY=...
- Add the alias for the
SEPOLIA_RPC_URL
below[rpc_endpoints]
.
[rpc_endpoints]
sepolia = "${SEPOLIA_RPC_URL}"
- In order to verify the smart contract on etherscan you will need to add etherscan api key inside
.env
file and add this configuration insidefoundry.toml
file so the command can detect the network automatically.
[etherscan]
sepolia = {key = "${ETHERSCAN_API_KEY}"}
You can read more about configurations here https://github.com/foundry-rs/foundry/tree/master/config
- FundMe contract require the
price-feed
address in the constructor parameter, Chainlink's ETH/USDprice-feed
address is0x694AA1769357215DE4FAC081bf1f309aDC325306
. Deploy the contract and pass the constructor arguments using command;
forge create FundMe --constructor-args 0x694AA1769357215DE4FAC081bf1f309aDC325306 --rpc-url sepolia --private-key $PRIVATE_KEY --verify