This project demonstrates how to add smart contracts to your project using Foundry. It provides a sample Message
contract, a test and deployment scripts.
$ forge build
$ forge test
$ forge fmt
$ forge snapshot
$ anvil
$ forge script script/Message.s.sol:MessageScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ cast <subcommand>
$ forge --help
$ anvil --help
$ cast --help
Foundry comes with local network anvil baked in, and allows us to deploy to our local network for quick testing locally.
To start a local network run:
make anvil
This will spin up a local blockchain with a determined private key, so you can use the same private key each time.
Then, you can deploy to it with:
make deploy-anvil contract=<CONTRACT_NAME>
Similar to deploy-sepolia
or deploy-mumbai
To add a chain, you'd just need to make a new entry in the Makefile
, and replace <YOUR_CHAIN>
with whatever your chain's information is.
deploy-<YOUR_CHAIN> :; @forge script script/${contract}.s.sol --rpc-url ${<YOUR_CHAIN>_RPC_URL} --private-key ${PRIVATE_KEY} --broadcast -vvvv