Foundry
Learn how to use Foundry to build and deploy smart contracts on Abstract.
To use Foundry to build smart contracts on Abstract, use the foundry-zksync fork.
YouTube Tutorial: Get Started with Foundry
Watch a step-by-step tutorial on how to get started with Foundry.
1. Install the foundry-zksync fork
This installation overrides any existing forge and cast binaries in
~/.foundry
. To revert to the standard foundry installation, follow the
Foundry installation
guide.
You can swap between the two installations at any time.
Install foundry-zksync
Install the foundryup-zksync
fork:
Run foundryup-zksync
to install the latest versions of the forge
and cast
binaries:
A successful installation will output the following message:
Verify installation
A helpful command to check if the installation was successful is:
If successful, it will output 20
lines of the available
options included in the foundry-zksync
fork.
2. Create a new project
Create a new project with forge
and change directory into the project.
3. Modify Foundry configuration
Update your foundry.toml
file to include the following options:
To use system contracts,
set the is_system
flag to true.
4. Write a smart contract
Modify the src/Counter.sol
file to include the following smart contract:
5. Compile the smart contract
Use the zksolc compiler (installed in the above steps) to compile smart contracts for Abstract:
You should now see the compiled smart contracts in the generated zkout
directory.
6. Deploy the smart contract
Add your private key
Create a new wallet keystore.
Enter your wallet’s private key when prompted & provide a password to encrypt it.
Deploy your smart contract
Run the following command to deploy your smart contracts:
Ensure myKeystore
is the name of the keystore file you created in the previous step.
If successful, the output should look similar to the following:
Verify an existing smart contract
In the above step, we verified the smart contract immediately after deployment.
To verify an existing smart contract on the block explorer, run the following command:
Note: Replace the contract path and address with your own.
Was this page helpful?