Deploy on Zircuit
A tutorial for deploying a smart contract on Zircuit using Foundry
Prerequisites
What is Foundry?
1
# Download and install Foundry
curl -L https://foundry.paradigm.xyz | bash
# Reload your shell configuration to make foundryup available
source ~/.zshrc # for zsh users
# OR
source ~/.bashrc # for bash users
# Install the latest version of Foundry tools
foundryupforge --version2
# Create a new Foundry project called 'counter'
forge init counter
# Navigate into the project directory
cd countercounter/
├── lib/ # Dependencies (like node_modules)
├── script/ # Deployment scripts
│ └── Counter.s.sol # Deployment script
├── src/ # Smart contract source files
│ └── Counter.sol # Main contract
├── test/ # Test files
│ └── Counter.t.sol # Contract tests
└── foundry.toml # Foundry configuration file3
cast wallet import mainnetKey --interactivecast wallet import testnetKey --interactive4
forge compile[⠊] Compiling...
[⠃] Compiling 23 files with Solc 0.8.30
[⠊] Solc 0.8.30 finished in 889.13ms
Compiler run successful!5
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
// State variable to store the counter value
uint256 public number;
// Function to set the counter to a specific value
function setNumber(uint256 newNumber) public {
number = newNumber;
}
// Function to increment the counter by 1
function increment() public {
number++;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
contract CounterScript is Script {
Counter public counter;
function setUp() public {}
function run() public {
// Start recording transactions for broadcast
vm.startBroadcast();
// Deploy the Counter contract
counter = new Counter();
// Stop recording transactions
vm.stopBroadcast();
}
}6
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
# Zircuit RPC configuration
[rpc_endpoints]
zircuit_mainnet = "https://mainnet.zircuit.com"
garfield_testnet = "https://garfield-testnet.zircuit.com"forge script script/Counter.s.sol:CounterScript \
--rpc-url zircuit_mainnet \
--account mainnetKey \
--broadcastforge script script/Counter.s.sol:CounterScript \
--rpc-url garfield_testnet \
--account testnetKey \
--broadcast[⠊] Compiling...
No files changed, compilation skipped
Enter keystore password:
Script ran successfully.
## Setting up 1 EVM.
==========================
Chain 48898
Estimated gas price: 0.000000509 gwei
Estimated total gas used for script: 203856
Estimated amount required: 0.000000000103762704 ETH
==========================
##### 48898
✅ [Success] Hash: 0x59bf94e4055ee2c4a71b9e6a7b7589ad3a5831ac38717c5f0d488eb4ed365a77
Contract Address: 0x6E69d4f9bc6a3E2f67d2D86877800482A8cdca40
Block: 8549829
Paid: 0.000000000039987315 ETH (156813 gas * 0.000000255 gwei)
✅ Sequence #1 on 48898 | Total Paid: 0.000000000039987315 ETH (156813 gas * avg 0.000000255 gwei)7
cast send <CONTRACT_ADDRESS> "increment()" \
--rpc-url https://mainnet.zircuit.com \
--account mainnetKeycast send <CONTRACT_ADDRESS> "increment()" \
--rpc-url https://garfield-testnet.zircuit.com \
--account testnetKeyblockHash 0x97162a12dc900daf598e18c7a026d0b7bea5b121fc20bd99600292b53ba8148b
blockNumber 8550305
contractAddress
cumulativeGasUsed 91965
effectiveGasPrice 255
from 0xbd9B49deFc88AC16D7fC0F7FE6Eb7E0F54F6317f
gasUsed 43482
...0x0000000000000000000000000000000000000000000000000000000000000001cast --to-dec 0x0000000000000000000000000000000000000000000000000000000000000001
# Output: 18
forge verify-contract <CONTRACT_ADDRESS> <SOURCE_FILE>:<CONTRACT_NAME> \
--chain-id 48900 \
--verifier sourcify \
--verifier-url https://sourcify.dev/serverforge verify-contract <CONTRACT_ADDRESS> <SOURCE_FILE>:<CONTRACT_NAME> \
--chain-id 48898 \
--verifier sourcify \
--verifier-url https://sourcify.dev/server9
# Run all tests
forge test
# Run tests with verbose output
forge test -vvv
# Run specific test
forge test --match-test testIncrementforge coverageforge test --gas-reportforge test --gas-reportLast updated
Was this helpful?