Foundry
Learn about how to develop on Sophon using Foundry
Installing foundry
On your command line, run:
You can find more information on the official zksync foundry website
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 - Note that this will only verify on Sophscan
Deployment using paymaster
- Same as Basic deployment but you append the
--zk-paymaster-address
flag - Note that the paymaster allows you to perform gasless transactions, 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 Basic deployment using script but you append the
--verify
flag - Note that this will only verify on Sophscan
Deployment using script with paymaster
- Same as Basic deployment using script but you append the
--zk-paymaster-address
flag - Note that 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 simplicity, 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 simplicity, you can copy paste the following script (note that here we are using
address(vm).call
): -
You can now run the following command:
Deployment using script with paymaster and verification
- Same as Basic deployment using script with paymaster but you append the
--verify
flag - Note that 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
with lib: forge build —zksync —libraries ./contracts/util/SignatureChecker.sol:SignatureChecker:0xb0A2cf27Bf984bd0c56dCFb37C9DA0F2c5028844
Contracts with constructor params
If your contracts 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 paymaster, you can use the flags
--verify
and/or----zk-paymaster-address
as explained above.
Was this page helpful?