Getting Started
Learn how to setup and use Foundry with your Validium project.
Last updated
Learn how to setup and use Foundry with your Validium project.
Last updated
Use forge test --zksync
to run tests written for your smart contracts.
For an overview of how to write tests using foundry-zksync
please refer to Foundry testing .
forge
forge build --zksync
forge build --zksync
is used for compiling smart contracts into Validium VM bytecode. The compiled files are stored in a structured directory at <PROJECT-ROOT>/zkout/
.
Command:
Options:
To get the list of all build
options run:
Besides standard options from original Foundry, there are Validium specific set of options:
--zk-startup[=<ENABLE_ZKVM_AT_STARTUP>]
Enable zkEVM at startup.
--zk-compile[=<COMPILE_FOR_ZKVM>]
Compile for zkEVM.
--zk-solc-path <ZK_SOLC_PATH>
Solc compiler path to use when compiling with zksolc.
--zk-enable-eravm-extensions[=<ENABLE_ERAVM_EXTENSIONS>]
Enable the system contract compilation mode.
--zk-force-evmla[=<FORCE_EVMLA>]
Forcibly switch to the EVM legacy assembly pipeline.
--zk-llvm-options <LLVM_OPTIONS>
ZkSolc extra LLVM options.
--zk-fallback-oz[=<FALLBACK_OZ>]
Try to recompile with -Oz if the bytecode is too large.
--zk-detect-missing-libraries
Detect missing libraries, instead of erroring.
-O, --zk-optimizer-mode <LEVEL>
Set the LLVM optimization parameter -O[0 | 1 | 2 | 3 | s | z]
. Use 3
for best performance and z
for minimal size.
--zk-optimizer
Enables optimizations.
--zk-avoid-contracts <AVOID_CONTRACTS>
Contracts to avoid compiling on Validium.
Examples:
Compile with default settings or specify zksolc
version:
forge create --zksync
Command:
forge create --zksync
deploys smart contracts to Validium.
Usage:
Options: To get the list of all create
options run:
Examples: Deploy Greeter.sol
to ZKsync Sepolia Testnet:
To deploy contracts like GreeterFactory.sol
, use the --zk-enable-eravm-extensions
flag.
Compile GreeterFactory.sol
:
Deploy GreeterFactory.sol
:
Deploy Greeter.sol
via GreeterFactory.sol
:
Interact with Greeter.sol
Output:
To decode the output to a readable string:
Output:
cast
This guide introduces you to fundamental interactions within the ZKsync chain using cast
, a component of the foundry-zksync
toolkit. Learn how to query chain IDs, retrieve client versions, check L2 ETH balances, obtain gas prices, and more.
Command:
Local Node: Retrieve the Chain ID for a local Validium node with:
Expected Output: 270
, indicating the Chain ID of your local Validium node.
Validium Sepolia Testnet: For the ZKsync Sepolia Testnet, use:
Expected Output: 300
, the Chain ID for the Validium Sepolia Testnet.
Knowing the client version is vital for compatibility checks and debugging:
Expected Output: ZKsync/v2.0
, denoting the client version.
Verify the Layer 2 (L2) balance of an account:
Expected Output: A numerical value, e.g., 774909739323110932
, representing the account's L2 balance.
Fetch the current gas price on the network for transaction cost estimations:
Expected Output: A value such as 100000000
, indicating the current gas price.
Gain insights into the latest block on the Validium chain:
Expected Output: Detailed information about the latest block, including base fee per gas, gas limit, block hash, and more.
Initiate transactions, such as contract function calls, using cast
:
Example:
This command calls the setGreeting
function of a contract, updating the greeting to "Hello, Validium!".
The following commands make use of Foundry keystore instead of private keys. .
If you're having an issues creating Foundry Validium project, please check out list of issues in or reach out to us by .