Foundry 开发教程
Linux 或者MacOS
curl -L https://foundry.paradigm.xyz | bash
Windows
Download and run rustup-init
from rustup.rs. It will start the installation in a console.
After this, run the following to build Foundry from source:
cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --locked
创建项目:
forge init hello_foundry
编译项目,会有out文件和cache文件夹 out类似ABI ,cache是forge重新编译时需要的文件
forge build
测试脚本
forge test
对于已存在的foundry项目,安装依赖
forge install
添加依赖,依赖会添加到 lib 文件夹内
forge install xxx/xxx 例如 forge install transmissions11/solmate
remapping ,
forge remappings
还可以自定义mapping,使用remappings.txt 维护
例如 solmate-utils/=lib/solmate/src/utils/
这样就可以使用 import "solmate-utils/Contract.sol" 这样的别名引入依赖
更新依赖
forge update 或者 forge update lib/solmate
移除依赖
forge remove solmate
hardhat 兼容
Forge also supports Hardhat-style projects where dependencies are npm packages (stored in node_modules) and contracts are stored in contracts as opposed to src. To enable Hardhat compatibility mode pass the --hh flag.
For automatic Hardhat support you can also pass the--hh
flag, which sets the following flags:--lib-paths node_modules --contracts contracts
.