Foundry
Installing Foundry
On your command line, run:
You can find more info on the official ZKsync Foundry website.
Create a New Project
This will create a new simple Foundry project with a Counter
contract.
Set Configs
A full baseline Foundry example can be found on our GitHub here.
Set your foundry.toml
and .env
as follows:
In order to obtain a Sophscan API Key, you need to create an account and get an API Key here.
Counter Contract Deployment
Basic Deployment
Deployment and Verification
Same as Basic Deployment but you append the --verify
flag
This will only verify on Sophscan
Deployment Using Paymaster
Same as Basic Deployment but you append the --zk-paymaster-address
flag
The paymaster allows you to perform gasless transactions, so there’s no need to have a $SOPH balance
Deployment With Paymaster and Verification (All-in-One)
Deploy Contracts Using Foundry Scripts
Deployment Using Script
Deployment Using Script and Verification
Same as Deployment Using Script but you append the --verify
flag
This will only verify on Sophscan
Deployment Using Script With Paymaster
Same as Deployment Using Script but you append the --zk-paymaster-address
flag
This will only verify on Sophscan
To use the paymaster within a script, you have 2 options: using a cheatcode or making a low-level call:
Using a Foundry Cheatcode
-
Install forge-zksync-std library
-
Use the vmExt.zkUsePaymaster cheatcode
-
For your convenience, you can copy-paste the following script:
You can now run the following command
Using a Low-Level Call (in Case You Can’t Install the Cheatcode Library)
For your convenience, you can copy-paste the following script:
Here we use address(vm).call
You can now run the following command:
Deployment Using Script With Paymaster and Verification
Same as Deployment Using Script With Paymaster but you append the --verify
flag
This will only verify on Sophscan
Contract Verification
If you want to verify an already deployed contract, you can do so on Sophscan (an Etherscan-like explorer) and/or on Sophon’s Explorer.
On Sophscan
On Sophon’s Explorer
Using Libraries
If your contract relies on external libraries, you need to build it with the linked libraries during deployment. For example:
This ensures the library is properly linked during the build and deploy process, enabling verification to succeed.
Contracts With Constructor Params
If your contract receives constructor params, you can use the --constructor-args
flag:
Modify your Counter contract to receive a constructor param:
You can now run:
To verify or use the paymaster, you can use the flags --verify
and/or ----zk-paymaster-address
as explained above.
Check if a contract is whitelisted by the paymaster
Before making calls to a newly deployed contract using a paymaster, it’s important to verify that the contract has been added to the paymaster’s whitelist. Our automated contract whitelisting service typically takes 2-3 seconds to whitelist new contracts under normal network conditions. While optional, checking the whitelist status before proceeding makes deployment scripts more robust by ensuring contracts are ready to interact with the paymaster.
The code below provides a reference implementation for checking the whitelist status:
Was this page helpful?