How to install Foundry on Windows
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 :
Installing Rust
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.
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 :
{
"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!