Foundry
Installing Foundry
On your command line, run:
Create a New Project
This will create a new simple Foundry project with a Counter
contract.
Set Configs
Use the following configs on your foundry.toml
Create an .env
file and set these env vars:
Counter Contract Deployment
Basic Deployment
Deployment and Verification
Same as Basic Deployment but you append the --verify
flag
Deployment Using Paymaster
Same as Basic Deployment but you append the --zk-paymaster-address
flag
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
Deployment Using Script With Paymaster
Same as Deployment Using Script but you append the --zk-paymaster-address
flag
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:
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
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:
--verify
and/or ----zk-paymaster-address
as explained above.Was this page helpful?