Skip to content

Commit 87f3448

Browse files
authored
docs: add StdConfig documentation to README (#817)
1 parent aeb45e9 commit 87f3448

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,52 @@ contract Bar {
221221

222222
Provides comprehensive assertion functions for testing, including equality checks (assertEq, assertNotEq), comparisons (assertLt, assertGt, assertLe, assertGe), approximate equality (assertApproxEqAbs, assertApproxEqRel), and boolean assertions (assertTrue, assertFalse). All assertions support multiple data types and optional custom error messages.
223223

224+
### StdConfig
225+
226+
This is a contract that parses a TOML configuration file and loads its variables into storage, automatically casting them on deployment. It assumes a TOML structure where top-level keys represent chain IDs or aliases. Under each chain key, variables are organized by type in separate sub-tables like `[<chain>.<type>]`, where type must be: `bool`, `address`, `bytes32`, `uint`, `int`, `string`, or `bytes`.
227+
228+
#### Example usage
229+
230+
```solidity
231+
232+
// SPDX-License-Identifier: MIT OR Apache-2.0
233+
pragma solidity ^0.8.13;
234+
235+
import "forge-std/Script.sol";
236+
import "forge-std/StdConfig.sol";
237+
238+
contract MyScript is Script {
239+
StdConfig config;
240+
241+
function run() public {
242+
// Load config (set writeToFile=true only in scripts to persist changes)
243+
config = new StdConfig("config.toml", false);
244+
245+
// Get values for the current chain
246+
uint256 myNumber = config.get("important_number").toUint256();
247+
address weth = config.get("weth").toAddress();
248+
address[] memory admins = config.get("whitelisted_admins").toAddressArray();
249+
250+
// Get values for a specific chain
251+
bool isLive = config.get(1, "is_live").toBool();
252+
253+
// Check if a key exists
254+
if (config.exists("optional_param")) {
255+
// ...
256+
}
257+
258+
// Get RPC URL for current or specific chain
259+
string memory rpc = config.getRpcUrl();
260+
string memory mainnetRpc = config.getRpcUrl(1);
261+
262+
// Get all configured chain IDs
263+
uint256[] memory chainIds = config.getChainIds();
264+
}
265+
}
266+
```
267+
268+
See the contract itself for supported TOML format and all available methods.
269+
224270
### `console.log`
225271

226272
Usage follows the same format as [Hardhat](https://hardhat.org/hardhat-network/reference/#console-log).

0 commit comments

Comments
 (0)