Installing Foundry
On your command line, run:Create a New Project
Counter contract.
Set Configs
A full baseline Foundry example can be found on our GitHub
here.
foundry.toml and .env as follows:
Counter Contract Deployment
Basic Deployment
Deployment and Verification
Same as Basic Deployment but you append the--verify flag and use the --verifier zksync flag to specify the verifier to use the Sophon Explorer or --verifier etherscan to use Sophscan.
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
Using a Foundry Cheatcode
- Install forge-zksync-std library
- Use the vmExt.zkUsePaymaster cheatcode
-
For your convenience, you can copy-paste the following script:
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).callDeployment 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 SophscanUsing Libraries
If your contract relies on external libraries, you need to build it with the linked libraries during deployment. For example: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: