Foundry安装

最近安装了Foundry智能合约开发工具,遇到一些小问题,在这里记录一下解决的过程。
以下是windows下的安装流程,mac等环境原理类似。因为主要是要解决网络问题。
用的是官网推荐的使用foundryup的方式,源代码编译的方式嫌麻烦没实践。

网络问题

笔者用的是Clash Verge, 设置服务模式,再开启Tun模式即可。Tun模式开启后会生成虚拟网卡,这样不止浏览器、包括终端和后面用到的Git Bash等全部流量就都会走代理进行加速了。

安装Foundry

首先windows下面先安装Git Bash,然后运行:

$ curl -L https://foundry.paradigm.xyz | bash

然后根据提示,运行 source /c/Users/admin/.bashrc或者新开一个终端窗口。再运行:

$ foundryup


.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx

 ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦         Portable and modular toolkit
 ╠╣  ║ ║ ║ ║ ║║║  ║║ ╠╦╝ ╚╦╝    for Ethereum Application Development
 ╚   ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═  ╩                 written in Rust.

.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx

Repo       : https://github.com/foundry-rs/
Book       : https://book.getfoundry.sh/
Chat       : https://t.me/foundry_rs/
Support    : https://t.me/foundry_support/
Contribute : https://github.com/orgs/foundry-rs/projects/2/

.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx

foundryup: installing foundry (version nightly, tag nightly)
foundryup: downloading latest forge, cast, anvil, and chisel
######################################################################## 100.0%
Archive:  /tmp/tmp.8yHoNyJ4Qq/foundry.zip
  inflating: /c/Users/admin/.foundry/bin/anvil.exe
  inflating: /c/Users/admin/.foundry/bin/cast.exe
  inflating: /c/Users/admin/.foundry/bin/chisel.exe
  inflating: /c/Users/admin/.foundry/bin/forge.exe
foundryup: downloading manpages
######################################################################## 100.0%
foundryup: installed - forge 0.2.0 (9a0f66e 2024-09-26T00:22:17.831423400Z)
foundryup: installed - cast 0.2.0 (9a0f66e 2024-09-26T00:22:17.595810000Z)
foundryup: installed - anvil 0.2.0 (9a0f66e 2024-09-26T00:22:15.870384700Z)
foundryup: installed - chisel 0.2.0 (9a0f66e 2024-09-26T00:22:15.879852900Z)
foundryup: done!

安装成功。

简单把玩一下

找个空文件夹,新建项目:

$ forge init hello_foundry
Initializing C:\Users\admin\foudrywork\hello_foundry...
Installing forge-std in C:/Users/admin/foudrywork/hello_foundry\lib\forge-std (url: Some("https://github.com/foundry-rs/forge-std"), tag: None)
Cloning into 'C:/Users/admin/foudrywork/hello_foundry/lib/forge-std'...
remote: Enumerating objects: 2447, done.
remote: Counting objects: 100% (2442/2442), done.
remote: Compressing objects: 100% (873/873), done.
remote: Total 2447 (delta 1628), reused 2260 (delta 1497), pack-reused 5 (from 1)
Receiving objects: 100% (2447/2447), 724.55 KiB | 1.35 MiB/s, done.
Resolving deltas: 100% (1628/1628), done.
warning: in the working copy of '.gitmodules', LF will be replaced by CRLF the next time Git touches it
    Installed forge-std v1.9.2
    Initialized forge project

这样就初始化建立了一个foundry项目hello_foundry,目录结构:

$ ls
README.md  foundry.toml  lib/  script/  src/  test/

然后构建,也就是编译:

$ forge build
[⠔] Compiling...
[⠒] Compiling 27 files with Solc 0.8.27
[⠑] Installing Solc version 0.8.27
[⠢] Successfully installed Solc 0.8.27
[⠆] Solc 0.8.27 finished in 5.43s
Compiler run successful!

然后是运行测试用例:

$ forge test
[⠊] Compiling...
No files changed, compilation skipped

Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 31054, ~: 31288)
[PASS] test_Increment() (gas: 31303)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 12.71ms (11.85ms CPU time)

Ran 1 test suite in 15.24ms (12.71ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)

参考

https://learnblockchain.cn/docs/foundry/i18n/zh/getting-started/installation.html
https://kerrynotes.com/clash-verge-tutorial/

posted on 2024-09-26 10:01  肥兔子爱豆畜子  阅读(56)  评论(0编辑  收藏  举报

导航