Skip to content

Commit

Permalink
feat(blog): add foundry global config
Browse files Browse the repository at this point in the history
  • Loading branch information
wiasliaw committed May 6, 2024
1 parent ae3cac6 commit 9899a86
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
quartz/.quartz-cache/
public/
content/.obsidian/workspace.json
content/.trash/
1 change: 1 addition & 0 deletions content/ctx_foundry_fv_model_checker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: "[context] enable formal verification in foundry"
tags:
- context
- foundry
---

Solidity compiler 內建一些 formal verification 的設定 (參考文件為 v0.8.25),簡介如下:
Expand Down
64 changes: 64 additions & 0 deletions content/ctx_foundry_global_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "[context] foundry global config"
tags:
- context
- foundry
---
Foundry 的設定檔分為 project level 和 global level,可以將一些設定放到 global config 裡面,以避免重複設定

## global config file

global config 為 `$HOME/.foundry/foundry.toml`,建立或是修改 `foundry.toml` 即可

## personal config

筆者是將有關 fork 和 verification 相關的參數都設定在全域,這樣就不需要為每個專案都設定一次 RPC endpoint 和 verification 相關的 api key。設定如下:

```toml
# $HOME/.foundry/foundry.toml
[rpc_endpoints]
mainnet = "https://..."

[etherscan]
mainnet = { key = "API_KEY", chain = "mainnet" }
```

## benefits

設定之後可以在測試中跑 fork test,填入設定的 endpoint name 即可:

```solidity
import "forge-std/Test.sol";
contract ForkTest is Test {
function testFork() external {
vm.createSelectFork("mainnet");
}
}
```

或是執行 deployment:

```solidity
import "forge-std/Script.sol";
contract ForkTest is Script {
function run() external {
vm.createSelectFork("mainnet");
}
}
```

```bash
forge script ... --rpc-url mainnet
```

相關的 cli 也可以使用已設定的 rpc endpoint,將 endpoint name 可以接在 `--rpc-url` 後面即可:

```bash
cast chain-id --rpc-url mainnet
```

## reference

- https://book.getfoundry.sh/reference/config/overview#global-configuration

0 comments on commit 9899a86

Please sign in to comment.