foundry-scripting-and-deploy
БесплатноБез исполняемых скриптовНе проверенUse when writing forge Script files, deploying contracts, handling per-chain configuration, or running post-deploy verification. Covers Script base…
от idchain-world★ 19 звёзд на GitHubОб этом скилле
Foundry Scripting and Deployment
You are writing a forge script or running a deployment. A script that touches mainnet is a piece of production code; treat it like one. The script is read, reviewed, and re-run. Hardcoded addresses and "I'll fix it later" comments are bugs in waiting.
The Iron Laws
- NEVER HARDCODE A PRIVATE KEY. Not in the script, not in a config file, not in a comment. Read from
vm.envUint("PRIVATE_KEY")or use an account / keystore flag. A leaked key takes seconds to drain. - NEVER COMMIT A
.envFILE..envbelongs in.gitignore. Commit.env.examplewith placeholders instead. If you discover a committed.env, rotate every key in it immediately — git history is forever. - NEVER RUN
forge script ... --broadcastWITHOUT A DRY RUN FIRST. Always run once without--broadcastto inspect the simulated traces. Production deploys that revert mid-way cost real gas and real time. - NEVER DEPLOY WITHOUT A CHAIN-ID GUARD. Every deploy script that encodes chain-specific addresses (oracles, bridges, tokens) asserts
block.chainidat the top. Deploying the mainnet config to a testnet is embarrassing; deploying the testnet config to mainnet is a catastrophe. - ALWAYS EMIT DEPLOYED ADDRESSES AS JSON. Downstream tooling (bots, subgraphs, frontends) reads your deploys. Log
{"contract":"Vault","address":"0x...","tx":"0x..."}so they can parse it, not a human-readable paragraph. - NEVER SKIP VERIFICATION. Pass
--verify(or runforge verify-contractafter) for every mainnet and testnet deploy. Unverified contracts are opaque; users cannot audit what they are signing into.
Script file shape
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {Script, console2} from "forge-std/Script.sol";
import {Vault} from "../src/Vault.sol";
contract DeployVault is Script {
function run() external returns (Vault vault) {
uint256 deployerPk = vm.envUint("DEPLOYER_PRIVATE_KEY");
address asset = vm.envAddress("VAULT_ASSET");
vm.startBroadcast(deployerPk);
vault = new Vault(asset);
vm.stopBroadcast();
console2.log("{\"contract\":\"Vault\",\"address\":\"%s\"}", address(vault));
}
}
Conventions:
- One deploy per script file.
DeployVault.s.soldeploysVault. Don't chain five unrelated deploys in one script. - Always
returnthe deployed contract. Makes composition cleaner when one script calls another. - Use
console2.lognotconsole.log.console2is the updated log API in newer forge-std and does not silently truncate.
Broadcasting forms
vm.startBroadcast has three forms. Pick deliberately.
| Form | Sender | When |
|---|---|---|
vm.startBroadcast() |
Default sender inferred from --sender, --private-key, --mnemonic, or --account flags passed to forge script. |
Local dev, flexible CI that provides creds via flags. |
vm.startBroadcast(uint256 pk) |
The address derived from pk. |
Explicit env-var key (vm.envUint). |
vm.startBroadcast(address from) |
from. Requires forge to know the key for from (via account, keystore, etc.). |
Deploy from a hardware wallet or a named keystore account. |
Prefer vm.startBroadcast() with CLI-level auth (--account deployer + Foundry keystore) over raw private keys in env. Keystore is encrypted at rest; .env is plaintext.
Environment variable handling
All runtime config comes from env. Read in the script, never from a committed constant.
uint256 deployerPk = vm.envUint("DEPLOYER_PRIVATE_KEY");
address registry = vm.envAddress("REGISTRY_ADDRESS");
string memory name = vm.envString("TOKEN_NAME");
bytes32 salt = vm.envBytes32("CREATE2_SALT");
uint256 chainId = block.chainid; // read from context, not env
Defaults for local anvil
When developers run the script against anvil, they shouldn't have to set every env var. Use vm.envOr for local defaults:
// Anvil's default first key, safe because it's well-known and worthless.
uint256 deployerPk = vm.envOr(
"DEPLOYER_PRIVATE_KEY",
uint256(0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80)
);
Rule: fallback defaults are only for local anvil. Never fall back on a mainnet path. The dev private key above is public — do not fund it.
.env.example
Commit this. Real values never.
# .env.example
DEPLOYER_PRIVATE_KEY=0x0000000000000000000000000000000000000000000000000000000000000000
RPC_URL_MAINNET=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
RPC_URL_SEPOLIA=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
ETHERSCAN_API_KEY=YOUR_ETHERSCAN_KEY
VAULT_ASSET=0x0000000000000000000000000000000000000000
Chain-ID guards
Multi-chain scripts read config by chain ID.
contract DeployVault is Script {
struct ChainConfig {
address asset;
address oracle;
}
function _configForChain() internal view returns (ChainConfig memory c) {
Установить foundry-scripting-and-deploy в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл foundry-scripting-and-deploy?
Use when writing forge Script files, deploying contracts, handling per-chain configuration, or running post-deploy verification. Covers Script base, vm.startBroadcast forms, env var handling, --rpc-url / --broadcast / --verify flags, CREATE2 deterministic deploys, multi-chain guards, and machine-readable JSON output.
Как установить скилл foundry-scripting-and-deploy?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл foundry-scripting-and-deploy запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic