Deploy and verify with Foundry scripts and Catapulta
Foundry is a very robust and beloved tool by the Solidity developers community, due to its blazing fast Rust EVM runtime, allowing to develop, test, debug and deploy smart contracts using Solidity and Foundry libraries.
Catapulta supports Foundry Solidity scripts, a way to orchestrate Solidity deployments using the same language, along with cheatcodes like vm.startBroadcast()
and vm.envUint("PRIVATE_KEY")
.
Deploy smart contracts with Foundry scripting and Catapulta CLI
For this tutorial, we will deploy a series of smart contracts, using Catapulta Foundry template repository as a reference to deploy smart contracts in the Sepolia EVM network, an Ethereum testnet.
Foundry allows you to deploy smart contracts with Solidity Scripts, let's check the scripts/Deploy.sol
file details:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Script} from "forge-std/Script.sol";
import {BatteringRam} from "../src/BatteringRam.sol";
import {Catapult} from "../src/Catapult.sol";
import {Trebuchet} from "../src/Trebuchet.sol";
contract DeploySiege is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
new BatteringRam(50);
new Catapult(100);
new Trebuchet(200);
vm.stopBroadcast();
}
}
We see the script will load a PRIVATE_KEY
from the environment variable, and broadcast with vm.startBroadcast
the following deployments: BatteringRam
, Catapult
and Trebuchet
smart contracts.
As a note, BatteringRam
is a factory contract that perform nested deployments of Champion
contracts during the constructor.
Let's deploy this Solidity Script with the following step by step guide:
- Git clone this repository and enter the repository directory:
git clone https://github.com/catapulta-sh/catapulta-foundry-template
cd catapulta-foundry-template
- Install forge dependencies and libraries.
forge install
- Generate a new private key with Catapulta CLI, that will be stored in your
.env
file, or add your own asPRIVATE_KEY
in the.env
file stored at the root of the project
npx catapulta wallet
# Output:
# Wallet address: 0x6B193d5604e09f1737E33cFc4B06fb3f2C7fC3CE
# Private key appended to your .env file.
- Get testnet funds for your EOA account address at the Alchemy Sepolia faucet.
- Sign up at Catapulta, follow the quick setup to create a project and generate a free
CATAPULTA_API_KEY
that must be stored in your.env
file. - Deploy with Catapulta CLI to the Sepolia network.
npx catapulta script scripts/Deploy.sol --network sepolia
# Output:
Catapulta.sh 🏏 Forge script deployment (0.2.8)
================================================
Project name: Ghost Deployments
Project URL: https://catapulta.sh/project/6106272a59b37a3a4a7afb55
Deployment UUID: 592a91ad-57c8-42c6-b371-2af0e170f31a
📀 Building artifacts...
🗜 Compressing artifacts...
📤 Uploading artifacts to the Catapulta DB...
✅ Artifacts uploaded successfully.
📡 Broadcasting deployments to Catapulta Gateway RPC:
📜 Running Foundry script: forge script scripts/DeployBasic.sol --rpc-url "https://catapulta.sh/api/run/add/chain/11125111/5922a91ad2-57228242c6-b37e-2af0e170f31a/gNd4vq8ApnRWhxwPJiMS" --broadcast --chain-id 11155111
[...]
==========================
ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
Total Paid: 0.000852774003979612 ETH (284258 gas * avg 3.000000014 gwei)
✅ Deployment successfully broadcasted
- Etherscan verification request sent. Check the dashboard for keeping track of verifications. If contracts are not verified in 10 minutes, contact support at Discord.
💾 Artifacts stored at:
- https://users-artifacts.s3.eu-west-1.amazonaws.com/51195a911d-57c8-42c6-b37e-2af0e170f31a-deployment-artifacts/artifacts.zip
📸 Check your deployment report at:
- https://catapulta.sh/project/6416272a5119b37a3a4a7afbd5/op/595f91ad-57c8-4112c6-b37e-2af0e170f31a
- Check the deployment report at the Catapulta Dashboard, and enjoy automated Etherscan verification without any Etherscan API keys.
Where are the RPC configs or Etherscan API keys stored?
Catapulta takes care of resolving the network name and routing your deployment script transactions into different RPC providers.
The Catapulta RPC Relay also detects if your transaction contains CREATE
or CREATE2
instructions, and automatically sends verification requests to Etherscan or the network block explorer REST API, to simplify and automate smart contracts verification in complex nested deployments.
Conclusion
Catapulta CLI allows you to deploy, verify, smart contracts using Foundry to +20 networks without RPC configurations or Etherscan API keys, and automatically generate deployment reports, resulting in a better deployment experience with less boilerplate code.
Sign up with Catapulta today for free and enjoy a better Solidity development experience, with zero-config deployments, automated verifications in block explorers and deployment reports which you can share within your team, clients or users.