Foundry is a blazing fast, portable, and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
- Forge: Ethereum testing framework (like Truffle, Hardhat, and DappTools).
- Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions, and getting chain data.
- Anvil: Local Ethereum node, akin to Ganache and Hardhat Network.
- Chisel: Fast, utilitarian, and verbose Solidity REPL.
- Official Foundry documentation: https://book.getfoundry.sh/
To upgrade Foundry to the latest version, run the following command:
foundryup
This will update all components of Foundry (Forge, Cast, Anvil, etc.) to the latest version.
To build the project:
forge build
To run tests:
forge test
To format Solidity code:
forge fmt
To take gas snapshots:
forge snapshot
To run a local Ethereum node (Anvil):
anvil
To deploy a smart contract using a script:
forge script script/YourScript.s.sol:YourScriptName --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast
Replace <your_rpc_url>
with the Ethereum node URL and <your_private_key>
with the private key of the account deploying the contract.
To interact with deployed contracts or query the blockchain:
cast <subcommand>
For example, sending ETH to an address:
cast send <recipient_address> --value 1ether --private-key <your_private_key> --rpc-url <your_rpc_url>
To get help on each tool, run:
forge --help
anvil --help
cast --help
Kurtosis is a tool that simplifies the development and testing of distributed systems by managing the lifecycle of complex environments, like blockchain testnets, microservices, and more. It allows you to define how services are deployed and orchestrated in your environment using predefined packages.
Kurtosis allows you to set up testnets or other services in enclaves (isolated environments) easily. These enclaves can contain Ethereum testnets, smart contract networks, or even your own infrastructure for development and testing purposes.
-
Install Kurtosis
If you don't have Kurtosis installed, follow the installation instructions from the Kurtosis documentation.
-
Start a Local Ethereum Testnet
To start an Ethereum testnet using Kurtosis, run the following command:
kurtosis run --enclave my-testnet github.com/ethpandaops/ethereum-package
This command will:
- run a new enclave (isolated environment) using the ethpandaops package, which sets up an Ethereum testnet.
-
Access the Ethereum Testnet
Once Kurtosis has started the testnet, it will output connection details such as RPC URLs and account information. Use these details to deploy and interact with smart contracts via Foundry's tools.
To deploy a UUPS upgradable contract using Forge, follow these steps:
-
Run the deployment script:
forge script script/DeployTestNFTV1.sol --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast
<your_rpc_url>
: The RPC URL of the Ethereum node or testnet (e.g., from Kurtosis).<your_private_key>
: The private key of the deployer's Ethereum account.
If you want to upgrade a previously deployed contract using the UUPS proxy pattern:
-
Run the upgrade script:
PROXY_ADDRESS=<proxy_address> forge script script/DeployTestNFTV2.sol --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast
<proxy_address>
: The address of the UUPS proxy for the contract you wish to upgrade.<your_rpc_url>
and<your_private_key>
are the same as before.
This will upgrade the implementation contract behind the UUPS proxy to the new version.
To deploy the initial version of the TestNFTV1
contract, use:
forge script script/DeployTestNFTV1.sol --rpc-url <rpc_url> --private-key <private_key> --broadcast
Replace <rpc_url>
with the testnet RPC URL (e.g., from Kurtosis), and <private_key>
with your private key.
Once TestNFTV1
is deployed, you can upgrade it to TestNFTV2
by running:
PROXY_ADDRESS=<proxy_address> forge script script/DeployTestNFTV2.sol --rpc-url <rpc_url> --private-key <private_key> --broadcast
Replace <proxy_address>
with the proxy address of the deployed contract.
After working with testnets in Kurtosis, it's a good practice to clean up resources. You can clean all running enclaves with:
kurtosis clean -a
This will stop and remove all running testnets or environments to free up resources.
This README.md
provides a detailed overview of using Foundry for Ethereum development and Kurtosis for managing testnets. It covers upgrading Foundry, deploying and upgrading contracts, interacting with smart contracts, and managing environments with Kurtosis.
If you encounter any issues, refer to the Foundry documentation or Kurtosis docs. Happy hacking!