foundry-zksync
v0.2.3Expose foundry-zksync (forge, cast, anvil-zksync) tools for zkSync Era development
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
init
Scaffold a new foundry project and add [profile.default.zksync] config (forge init)
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path where the new project should be created |
name | string | Project name (used as directory name if projectPath is the parent) |
noCommit | boolean | If true, skip the initial git commit (--no-commit) |
noGit | boolean | If true, skip git initialization (--no-git) |
template | string | GitHub template to use, e.g. 'PaulRBerg/foundry-template' |
install
Install dependencies for a foundry project (forge install)
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
dependencies | array | Dependencies to install, e.g. ['OpenZeppelin/openzeppelin-contracts', 'transmissions11/solmate']. If omitted, installs all existing dependencies from foundry.toml. |
noCommit | boolean | If true, passes --no-commit to skip creating a git commit for the install |
clean
Remove build artifacts (out/ and zkout/) from a foundry project (forge clean)
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
compile
Compile a foundry-zksync project (forge build --zksync). Check foundry.toml for [profile.X.zksync] sections — if zkSync sources live under a specific profile (e.g. 'zksync'), pass that as the profile argument.
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
test
Run tests in a foundry-zksync project (forge test --zksync). Check foundry.toml for [profile.X] sections — if the test directory differs per profile (e.g. profile 'zksync' has test = 'zksync/tests'), pass the correct profile argument.
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
contractFilter | string | Regex passed to --match-contract to filter which test contracts run |
filter | string | Regex passed to --match-test to filter which test functions run |
pathFilter | string | Glob passed to --match-path to filter which test files run, e.g. 'test/unit/*' |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
verbosity | integer | Verbosity level (0-5), maps to -v through -vvvvv. Higher = more trace output |
run_script
Run a forge script targeting zkSync (forge script --zksync)
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
scriptPath * | string | Path to the Solidity script file, e.g. script/Deploy.s.sol |
account | string | Named keystore account from ~/.foundry/keystores (recommended for production). Create one with: cast wallet import <name> --interactive |
aws | boolean | Sign with AWS KMS (requires AWS_KMS_KEY_ID env var) |
broadcast | boolean | If true, passes --broadcast to actually send transactions on-chain |
extraArgs | array | Additional CLI flags, each as a separate array element, e.g. ['--verify', '--etherscan-api-key', 'abc'] |
from | string | Sender address, used with --unlocked or hardware wallets. Maps to --from for cast/deploy, --sender for forge script. |
gcp | boolean | Sign with Google Cloud KMS (requires GCP_PROJECT_ID, GCP_LOCATION, GCP_KEY_RING, GCP_KEY_NAME, GCP_KEY_VERSION env vars) |
keystore | string | Path to an encrypted keystore JSON file |
keystorePassword | string | Keystore password (prefer passwordFile to keep it out of process args) |
ledger | boolean | Sign with a Ledger hardware wallet |
passwordFile | string | Path to a file containing the keystore password |
privateKey | string | Raw private key for signing. Only use for local development with well-known test keys (e.g. anvil-zksync accounts). For production, use 'account' (named keystore) or hardware wallets instead. |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
rpcUrl | string | RPC URL to fork from or broadcast to |
sender | string | Address to use as msg.sender for the script simulation (--sender). Useful for dry-run without a signing key. |
slow | boolean | If true, sends transactions sequentially (--slow). Required on ZK chains which do not support transaction batching. |
trezor | boolean | Sign with a Trezor hardware wallet |
unlocked | boolean | Use eth_sendTransaction with --from address (no local signing). For nodes that manage keys natively. |
deploy
Deploy a contract to a zkSync network (forge create --zksync). Returns structured output with contract address, tx hash, and deployer.
| Parameter | Type | Description |
|---|---|---|
contractPath * | string | Contract identifier in the form src/MyContract.sol:MyContract |
projectPath * | string | Absolute path to the foundry project directory |
rpcUrl * | string | RPC URL of the target zkSync network |
account | string | Named keystore account from ~/.foundry/keystores (recommended for production). Create one with: cast wallet import <name> --interactive |
aws | boolean | Sign with AWS KMS (requires AWS_KMS_KEY_ID env var) |
broadcast | boolean | If true, actually broadcast the deployment transaction on-chain. Without this, forge create runs in dry-run mode. |
constructorArgs | array | Constructor arguments, each as a separate string. Solidity types are ABI-encoded by forge, e.g. ['0xaddr', '100', 'hello'] |
extraArgs | array | Additional CLI flags, each as a separate array element |
from | string | Sender address, used with --unlocked or hardware wallets. Maps to --from for cast/deploy, --sender for forge script. |
gcp | boolean | Sign with Google Cloud KMS (requires GCP_PROJECT_ID, GCP_LOCATION, GCP_KEY_RING, GCP_KEY_NAME, GCP_KEY_VERSION env vars) |
keystore | string | Path to an encrypted keystore JSON file |
keystorePassword | string | Keystore password (prefer passwordFile to keep it out of process args) |
ledger | boolean | Sign with a Ledger hardware wallet |
passwordFile | string | Path to a file containing the keystore password |
privateKey | string | Raw private key for signing. Only use for local development with well-known test keys (e.g. anvil-zksync accounts). For production, use 'account' (named keystore) or hardware wallets instead. |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
trezor | boolean | Sign with a Trezor hardware wallet |
unlocked | boolean | Use eth_sendTransaction with --from address (no local signing). For nodes that manage keys natively. |
verifierUrl | string | Block explorer verification API URL (e.g. https://api-era.zksync.network/api) |
verify | boolean | If true, verify the contract on a block explorer after deployment |
verify
Verify a deployed contract on a block explorer (forge verify-contract --zksync). Supports Etherscan (requires API key) and zkSync Explorer (no key needed).
| Parameter | Type | Description |
|---|---|---|
contractAddress * | string | Deployed contract address to verify |
contractPath * | string | Contract identifier, e.g. src/MyContract.sol:MyContract |
projectPath * | string | Absolute path to the foundry project directory |
verifier * | string | Verification backend. 'etherscan' requires an API key, 'zksync' uses the zkSync Explorer (no API key needed). |
verifierUrl * | string | Verifier API URL. Etherscan mainnet: https://api-era.zksync.network/api, Etherscan testnet: https://api-sepolia-era.zksync.network/api, Explorer mainnet: https://explorer.zksync.io/contract_verificati… |
compilerVersion | string | Compiler version used for deployment, e.g. v0.8.26+commit.8a97fa7a |
constructorArgs | string | ABI-encoded constructor arguments (hex string, no 0x prefix) |
etherscanApiKey | string | Etherscan API key (required when verifier is 'etherscan') |
extraArgs | array | Additional CLI flags |
numOptimizations | number | Number of optimization runs used during compilation |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
retries | integer | Number of verification retries (default: 2, max: 10). Minimum is 1. Forge retries on transient failures. |
gas_report
Run tests and generate a gas usage report (forge test --zksync --gas-report). Note: zkSync gas values are aggregate-only (no computation/pubdata breakdown).
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
contractFilter | string | Regex passed to --match-contract to filter which contracts appear in the report |
filter | string | Regex passed to --match-test to filter which test functions run |
pathFilter | string | Glob passed to --match-path to filter which test files run |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
snapshot
Create or compare gas snapshots (forge snapshot --zksync). Use diff=true to compare against existing .gas-snapshot, check=true to fail on changes.
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
check | boolean | If true, compare against existing snapshot and fail if any gas values changed |
contractFilter | string | Regex passed to --match-contract to filter which test contracts run |
diff | boolean | If true, compare against the existing .gas-snapshot file and show differences |
filter | string | Regex passed to --match-test to filter which test functions run |
profile | string | Foundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'. |
read_foundry_toml
Read and return the contents of foundry.toml from a project. Useful for inspecting profiles, zkSync config, library links, and other settings.
| Parameter | Type | Description |
|---|---|---|
projectPath * | string | Absolute path to the foundry project directory |
summary | boolean | If true, return a summary highlighting zkSync-relevant config (profiles, zksolc version, compile mode, libraries) instead of raw TOML. |
explain
Explain raw output from foundry-zksync: error messages, logs, or transactions. Matches against a knowledge base of known zkSync gotchas and returns actionable advice. Use context='general' for background on what foundry-zksync is and how it works.
| Parameter | Type | Description |
|---|---|---|
rawText * | string | Raw text to explain — can be an error message, forge log output, transaction hash, ABI-encoded data, or a general question about foundry-zksync |
context | string | Hint for what kind of text this is. 'general' prepends foundry-zksync background context. Defaults to general. |
cast_abi_encode
ABI-encode values for a given Solidity function/constructor signature (cast abi-encode)
| Parameter | Type | Description |
|---|---|---|
args * | array | Values to encode, matching the signature types in order, e.g. ["0x1234...", "1000000"] |
signature * | string | Solidity function or constructor signature, e.g. "constructor(address,uint256)" or "transfer(address,uint256)" |
cast_abi_decode
Decode ABI-encoded hex data back into human-readable values (cast abi-decode)
| Parameter | Type | Description |
|---|---|---|
data * | string | Hex-encoded ABI data to decode (0x-prefixed) |
signature * | string | Solidity function signature whose output types to decode against, e.g. "balanceOf(address)(uint256)" or "transfer(address,uint256)" |
input | boolean | If true, decode as input data (function args). If false/omitted, decode as output data (return values). |
cast_calldata_decode
Decode raw transaction calldata (with 4-byte selector) into function arguments (cast calldata-decode)
| Parameter | Type | Description |
|---|---|---|
calldata * | string | Raw transaction calldata (0x-prefixed, includes the 4-byte selector) |
signature * | string | Function signature, e.g. "transfer(address,uint256)" |
cast_call
Read-only call to a deployed contract — no gas spent, no state change (cast call)
| Parameter | Type | Description |
|---|---|---|
rpcUrl * | string | RPC URL of the zkSync network to call against |
signature * | string | Function signature with return type, e.g. "balanceOf(address)(uint256)" or "name()(string)" |
to * | string | Address of the contract to call |
args | array | Function arguments in order, e.g. ['0x1234...'] |
blockTag | string | Block to query at, e.g. "latest", "pending", or a block number |
cast_send
Send a state-changing transaction to a deployed contract (cast send)
| Parameter | Type | Description |
|---|---|---|
rpcUrl * | string | RPC URL of the zkSync network |
signature * | string | Function signature, e.g. "transfer(address,uint256)" |
to * | string | Address of the contract to send the transaction to |
account | string | Named keystore account from ~/.foundry/keystores (recommended for production). Create one with: cast wallet import <name> --interactive |
args | array | Function arguments in order |
aws | boolean | Sign with AWS KMS (requires AWS_KMS_KEY_ID env var) |
from | string | Sender address, used with --unlocked or hardware wallets. Maps to --from for cast/deploy, --sender for forge script. |
gasLimit | string | Gas limit override |
gcp | boolean | Sign with Google Cloud KMS (requires GCP_PROJECT_ID, GCP_LOCATION, GCP_KEY_RING, GCP_KEY_NAME, GCP_KEY_VERSION env vars) |
keystore | string | Path to an encrypted keystore JSON file |
keystorePassword | string | Keystore password (prefer passwordFile to keep it out of process args) |
ledger | boolean | Sign with a Ledger hardware wallet |
passwordFile | string | Path to a file containing the keystore password |
privateKey | string | Raw private key for signing. Only use for local development with well-known test keys (e.g. anvil-zksync accounts). For production, use 'account' (named keystore) or hardware wallets instead. |
trezor | boolean | Sign with a Trezor hardware wallet |
unlocked | boolean | Use eth_sendTransaction with --from address (no local signing). For nodes that manage keys natively. |
value | string | ETH value to send with the transaction, e.g. "0.1ether" or amount in wei |
cast_balance
Query the ETH balance of an address (cast balance)
| Parameter | Type | Description |
|---|---|---|
address * | string | Address to query the balance of |
rpcUrl * | string | RPC URL of the network |
blockTag | string | Block to query at, e.g. "latest", "pending", or a block number |
ether | boolean | If true, format the output in ether instead of wei |
cast_nonce
Query the transaction nonce of an address (cast nonce). Note: on zkSync this returns the TX nonce only, not the deploy nonce.
| Parameter | Type | Description |
|---|---|---|
address * | string | Address to query the nonce of |
rpcUrl * | string | RPC URL of the network |
blockTag | string | Block to query at, e.g. "latest", "pending", or a block number |
get_zksync_docs
Look up foundry-zksync documentation by topic. Returns URLs to the foundry-zksync book for installation, config, testing, deployment, cheatcodes, nonces, factory deps, paymasters, verification, and more. Use topic='list' to see all available topics.
| Parameter | Type | Description |
|---|---|---|
topic * | string | Topic to look up in the foundry-zksync book. Examples: 'installation', 'forge-test', 'cheatcodes', 'deployment', 'config', 'zksync-config', 'nonces', 'factory-deps', 'paymaster', 'verification', 'cast… |
anvil_zksync
Start or check a local anvil-zksync development node. Supports forking from mainnet/testnet. Default port: 8011.
| Parameter | Type | Description |
|---|---|---|
action * | string | 'start' launches anvil-zksync in the background and returns when ready. 'check' tests if anvil-zksync is reachable at the given port. |
accounts | number | Number of funded accounts to generate (default: 10) |
balance | number | ETH balance for each generated account in ether (default: 10000) |
forkBlockNumber | number | Block number to fork from (requires forkUrl) |
forkUrl | string | RPC URL to fork from, e.g. https://mainnet.era.zksync.io |
port | number | Port to listen on (default: 8011) |