foundry-zksync

v0.2.3
io.github.Jrigada/foundry-zksync Checked 2 hours ago Published 9 months ago

Expose 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)

ParameterTypeDescription
projectPath *stringAbsolute path where the new project should be created
namestringProject name (used as directory name if projectPath is the parent)
noCommitbooleanIf true, skip the initial git commit (--no-commit)
noGitbooleanIf true, skip git initialization (--no-git)
templatestringGitHub template to use, e.g. 'PaulRBerg/foundry-template'

install

Install dependencies for a foundry project (forge install)

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
dependenciesarrayDependencies to install, e.g. ['OpenZeppelin/openzeppelin-contracts', 'transmissions11/solmate']. If omitted, installs all existing dependencies from foundry.toml.
noCommitbooleanIf 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)

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
profilestringFoundry 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.

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
profilestringFoundry 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.

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
contractFilterstringRegex passed to --match-contract to filter which test contracts run
filterstringRegex passed to --match-test to filter which test functions run
pathFilterstringGlob passed to --match-path to filter which test files run, e.g. 'test/unit/*'
profilestringFoundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'.
verbosityintegerVerbosity level (0-5), maps to -v through -vvvvv. Higher = more trace output

run_script

Run a forge script targeting zkSync (forge script --zksync)

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
scriptPath *stringPath to the Solidity script file, e.g. script/Deploy.s.sol
accountstringNamed keystore account from ~/.foundry/keystores (recommended for production). Create one with: cast wallet import <name> --interactive
awsbooleanSign with AWS KMS (requires AWS_KMS_KEY_ID env var)
broadcastbooleanIf true, passes --broadcast to actually send transactions on-chain
extraArgsarrayAdditional CLI flags, each as a separate array element, e.g. ['--verify', '--etherscan-api-key', 'abc']
fromstringSender address, used with --unlocked or hardware wallets. Maps to --from for cast/deploy, --sender for forge script.
gcpbooleanSign with Google Cloud KMS (requires GCP_PROJECT_ID, GCP_LOCATION, GCP_KEY_RING, GCP_KEY_NAME, GCP_KEY_VERSION env vars)
keystorestringPath to an encrypted keystore JSON file
keystorePasswordstringKeystore password (prefer passwordFile to keep it out of process args)
ledgerbooleanSign with a Ledger hardware wallet
passwordFilestringPath to a file containing the keystore password
privateKeystringRaw 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.
profilestringFoundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'.
rpcUrlstringRPC URL to fork from or broadcast to
senderstringAddress to use as msg.sender for the script simulation (--sender). Useful for dry-run without a signing key.
slowbooleanIf true, sends transactions sequentially (--slow). Required on ZK chains which do not support transaction batching.
trezorbooleanSign with a Trezor hardware wallet
unlockedbooleanUse 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.

ParameterTypeDescription
contractPath *stringContract identifier in the form src/MyContract.sol:MyContract
projectPath *stringAbsolute path to the foundry project directory
rpcUrl *stringRPC URL of the target zkSync network
accountstringNamed keystore account from ~/.foundry/keystores (recommended for production). Create one with: cast wallet import <name> --interactive
awsbooleanSign with AWS KMS (requires AWS_KMS_KEY_ID env var)
broadcastbooleanIf true, actually broadcast the deployment transaction on-chain. Without this, forge create runs in dry-run mode.
constructorArgsarrayConstructor arguments, each as a separate string. Solidity types are ABI-encoded by forge, e.g. ['0xaddr', '100', 'hello']
extraArgsarrayAdditional CLI flags, each as a separate array element
fromstringSender address, used with --unlocked or hardware wallets. Maps to --from for cast/deploy, --sender for forge script.
gcpbooleanSign with Google Cloud KMS (requires GCP_PROJECT_ID, GCP_LOCATION, GCP_KEY_RING, GCP_KEY_NAME, GCP_KEY_VERSION env vars)
keystorestringPath to an encrypted keystore JSON file
keystorePasswordstringKeystore password (prefer passwordFile to keep it out of process args)
ledgerbooleanSign with a Ledger hardware wallet
passwordFilestringPath to a file containing the keystore password
privateKeystringRaw 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.
profilestringFoundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'.
trezorbooleanSign with a Trezor hardware wallet
unlockedbooleanUse eth_sendTransaction with --from address (no local signing). For nodes that manage keys natively.
verifierUrlstringBlock explorer verification API URL (e.g. https://api-era.zksync.network/api)
verifybooleanIf 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).

ParameterTypeDescription
contractAddress *stringDeployed contract address to verify
contractPath *stringContract identifier, e.g. src/MyContract.sol:MyContract
projectPath *stringAbsolute path to the foundry project directory
verifier *stringVerification backend. 'etherscan' requires an API key, 'zksync' uses the zkSync Explorer (no API key needed).
verifierUrl *stringVerifier 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…
compilerVersionstringCompiler version used for deployment, e.g. v0.8.26+commit.8a97fa7a
constructorArgsstringABI-encoded constructor arguments (hex string, no 0x prefix)
etherscanApiKeystringEtherscan API key (required when verifier is 'etherscan')
extraArgsarrayAdditional CLI flags
numOptimizationsnumberNumber of optimization runs used during compilation
profilestringFoundry profile to use (maps to FOUNDRY_PROFILE env var). Selects a [profile.<name>] section from foundry.toml, e.g. 'zksync', 'ci', 'production'.
retriesintegerNumber 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).

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
contractFilterstringRegex passed to --match-contract to filter which contracts appear in the report
filterstringRegex passed to --match-test to filter which test functions run
pathFilterstringGlob passed to --match-path to filter which test files run
profilestringFoundry 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.

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
checkbooleanIf true, compare against existing snapshot and fail if any gas values changed
contractFilterstringRegex passed to --match-contract to filter which test contracts run
diffbooleanIf true, compare against the existing .gas-snapshot file and show differences
filterstringRegex passed to --match-test to filter which test functions run
profilestringFoundry 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.

ParameterTypeDescription
projectPath *stringAbsolute path to the foundry project directory
summarybooleanIf 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.

ParameterTypeDescription
rawText *stringRaw text to explain — can be an error message, forge log output, transaction hash, ABI-encoded data, or a general question about foundry-zksync
contextstringHint 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)

ParameterTypeDescription
args *arrayValues to encode, matching the signature types in order, e.g. ["0x1234...", "1000000"]
signature *stringSolidity 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)

ParameterTypeDescription
data *stringHex-encoded ABI data to decode (0x-prefixed)
signature *stringSolidity function signature whose output types to decode against, e.g. "balanceOf(address)(uint256)" or "transfer(address,uint256)"
inputbooleanIf 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)

ParameterTypeDescription
calldata *stringRaw transaction calldata (0x-prefixed, includes the 4-byte selector)
signature *stringFunction signature, e.g. "transfer(address,uint256)"

cast_call

Read-only call to a deployed contract — no gas spent, no state change (cast call)

ParameterTypeDescription
rpcUrl *stringRPC URL of the zkSync network to call against
signature *stringFunction signature with return type, e.g. "balanceOf(address)(uint256)" or "name()(string)"
to *stringAddress of the contract to call
argsarrayFunction arguments in order, e.g. ['0x1234...']
blockTagstringBlock to query at, e.g. "latest", "pending", or a block number

cast_send

Send a state-changing transaction to a deployed contract (cast send)

ParameterTypeDescription
rpcUrl *stringRPC URL of the zkSync network
signature *stringFunction signature, e.g. "transfer(address,uint256)"
to *stringAddress of the contract to send the transaction to
accountstringNamed keystore account from ~/.foundry/keystores (recommended for production). Create one with: cast wallet import <name> --interactive
argsarrayFunction arguments in order
awsbooleanSign with AWS KMS (requires AWS_KMS_KEY_ID env var)
fromstringSender address, used with --unlocked or hardware wallets. Maps to --from for cast/deploy, --sender for forge script.
gasLimitstringGas limit override
gcpbooleanSign with Google Cloud KMS (requires GCP_PROJECT_ID, GCP_LOCATION, GCP_KEY_RING, GCP_KEY_NAME, GCP_KEY_VERSION env vars)
keystorestringPath to an encrypted keystore JSON file
keystorePasswordstringKeystore password (prefer passwordFile to keep it out of process args)
ledgerbooleanSign with a Ledger hardware wallet
passwordFilestringPath to a file containing the keystore password
privateKeystringRaw 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.
trezorbooleanSign with a Trezor hardware wallet
unlockedbooleanUse eth_sendTransaction with --from address (no local signing). For nodes that manage keys natively.
valuestringETH 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)

ParameterTypeDescription
address *stringAddress to query the balance of
rpcUrl *stringRPC URL of the network
blockTagstringBlock to query at, e.g. "latest", "pending", or a block number
etherbooleanIf 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.

ParameterTypeDescription
address *stringAddress to query the nonce of
rpcUrl *stringRPC URL of the network
blockTagstringBlock 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.

ParameterTypeDescription
topic *stringTopic 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.

ParameterTypeDescription
action *string'start' launches anvil-zksync in the background and returns when ready. 'check' tests if anvil-zksync is reachable at the given port.
accountsnumberNumber of funded accounts to generate (default: 10)
balancenumberETH balance for each generated account in ether (default: 10000)
forkBlockNumbernumberBlock number to fork from (requires forkUrl)
forkUrlstringRPC URL to fork from, e.g. https://mainnet.era.zksync.io
portnumberPort to listen on (default: 8011)