From 04a840fa9409e9a6bfc4b93784caebb1366c57a9 Mon Sep 17 00:00:00 2001 From: emmmm <155267286+eeemmmmmm@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:16:45 -0300 Subject: [PATCH] docs: add StdConfig documentation to README --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index d255b2ab..13015e4f 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,52 @@ contract Bar { 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. +### StdConfig + +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 `[.]`, where type must be: `bool`, `address`, `bytes32`, `uint`, `int`, `string`, or `bytes`. + +#### Example usage + +```solidity + +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.13; + +import "forge-std/Script.sol"; +import "forge-std/StdConfig.sol"; + +contract MyScript is Script { + StdConfig config; + + function run() public { + // Load config (set writeToFile=true only in scripts to persist changes) + config = new StdConfig("config.toml", false); + + // Get values for the current chain + uint256 myNumber = config.get("important_number").toUint256(); + address weth = config.get("weth").toAddress(); + address[] memory admins = config.get("whitelisted_admins").toAddressArray(); + + // Get values for a specific chain + bool isLive = config.get(1, "is_live").toBool(); + + // Check if a key exists + if (config.exists("optional_param")) { + // ... + } + + // Get RPC URL for current or specific chain + string memory rpc = config.getRpcUrl(); + string memory mainnetRpc = config.getRpcUrl(1); + + // Get all configured chain IDs + uint256[] memory chainIds = config.getChainIds(); + } +} +``` + +See the contract itself for supported TOML format and all available methods. + ### `console.log` Usage follows the same format as [Hardhat](https://hardhat.org/hardhat-network/reference/#console-log).