On your command line, run:
You can find more info on the official ZKsync Foundry website.
This will create a new simple Foundry project with a Counter
contract.
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.
If you run into deployment or interaction issues, always check for possible short-circuit errors
caused by environment variables not being properly exposed to the foundry script. You can do so by
running source .env
before running the script or check the variable in your env by running echo $VARIABLE_NAME
.
Same as Basic Deployment but you append the --verify
flag
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
Same as Deployment Using Script but you append the --verify
flag
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:
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
For your convenience, you can copy-paste the following script:
address(vm).call
You can now run the following command:
Same as Deployment Using Script With Paymaster but you append the --verify
flag
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
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.
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.
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:
On your command line, run:
You can find more info on the official ZKsync Foundry website.
This will create a new simple Foundry project with a Counter
contract.
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.
If you run into deployment or interaction issues, always check for possible short-circuit errors
caused by environment variables not being properly exposed to the foundry script. You can do so by
running source .env
before running the script or check the variable in your env by running echo $VARIABLE_NAME
.
Same as Basic Deployment but you append the --verify
flag
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
Same as Deployment Using Script but you append the --verify
flag
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:
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
For your convenience, you can copy-paste the following script:
address(vm).call
You can now run the following command:
Same as Deployment Using Script With Paymaster but you append the --verify
flag
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
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.
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.
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: