Foundry Installation on Windows

Rego
4 min readMay 17, 2023

Foundry is a powerful smart contract development toolchain that streamlines the entire process from managing dependencies to deploying and interacting with the blockchain. With Foundry, developers can effortlessly compile projects, run tests, and execute Solidity scripts via the command-line interface. As someone who has recently transitioned from Truffle to Foundry, I have been amazed by the incredible efficiency and improved outcomes it offers. In this article, I will guide you through the step-by-step process of installing Foundry on a Windows 10 machine, enabling you to unlock the full potential of this exceptional development tool.

You can check it out at https://github.com/RegoDefies/Foundry-Install-Windows too. And for more info, go to https://book.getfoundry.sh or https://github.com/foundry-rs.

Installing Foundry

To install Foundry, you’ll need cargo, the toolchain from Rust compiler, and Visual Studio runtime libraries. 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, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Installing Rust

  1. Download rust from (https://rustup.rs/)[https://rustup.rs/].
  2. Run rustup-init.exe with admin privileges
  • Select 1 : Proceed with installation (default)
  • Press Enter to continue (to load the reload PATH with cargo bin’s directory at%USERPROFILE%.cargo\bin )

Installing Visual Studio (if you don’t have it)

If you don’t have Visual Studio installed with “Desktop Development with C++”, you won’t be able to install rust. So, install VS.

You can skip this step if you already have the libraries installed on your machine.

Installing foundry-cli, anvil and chisel

If you don’t have github bash, install it. You do, right? Anyway, if not, https://git-scm.com/downloads.

  1. Using gitbash, install foundry-cli, anvil and chisel using
cargo install --git https://github.com/foundry-rs/foundry --profile local --force foundry-cli anvil chisel

and wait…

After installing with success, test if the versions are as expected, using

forge --version && cast --version && anvil --version

To initialize a project

Use

forge init --force

To install openzeppelin contracts (or other libraries)

Go to github and check the path is correct : we will install https://github.com/OpenZeppelin/openzeppelin-contracts, so by doing :

forget install OpenZeppelin/openzeppelin-contracts
  1. If you get the error message

The target directory is a part of or on its own an already initialized git repository, and it requires clean working and staging areas, including no untracked files. Check the current git repository’s status with git status. Then, you can track files with git add ... and then commit them with git commit, ignore them in the .gitignore file, or run this command again with the --no-commit flag. If none of the previous steps worked, please open an issue at: https://github.com/foundry-rs/foundry/issues/new/choose

install using

forget install OpenZeppelin/openzeppelin-contracts --no-commit

2. Now include the new lib into the remappings, so add the following line into foundry.toml file :
remappings = ["@openzeppelin=lib/openzeppelin-contracts"]

3. And if you are using VSCode, or VSCodium :

  • Include the lib folder into the Solidity defaults. So in settings, look for Solidity, and include lib at the Solidity: Package Default Dependencies Directory.
  • And in the Solidity: Remappings click at Edit in settings.json
  • Also include the forge-std and ds-test libs into settings.json file as indicated below, to allow full compilation at the IDE.
{
"workbench.colorTheme": "Default Light+",
"solidity.packageDefaultDependenciesDirectory": "\"node_modules\", \"lib\"",
"solidity.remappings": [
"forge-std=lib/forge-std/src",
"ds-test=lib/forge-std/lib/ds-test/src",
"@openzeppelin=lib/openzeppelin-contracts"
]
}

Conclusion

Foundry is a powerful and user-friendly smart contract development toolchain that simplifies the entire blockchain development process. With its streamlined functionality, developers can focus on their project, without worrying about the technicalities of the development environment. By following the steps outlined in this article, you can quickly and easily install Foundry on a Windows operating system and start developing smart contracts with ease. So, if you want to take your blockchain development to the next level, give Foundry a try today and experience the efficiency and ease-of-use that it has to offer!

--

--

Rego

23y+ SwE | 4y+ Blockchain || Web3 Architect/Dev. | Sr/Arch SwEng.