Quickstart with Foundry
Create, deploy and inspect your first contract with Foundry.
Prerequisites#
- Install Foundry from its official guide(opens in a new tab).
- Create a wallet account used only for testing and claim tZROAR from the faucet(opens in a new tab).
Create a project#
forge init my-zroarus-app
cd my-zroarus-appThis creates a sample Counter contract in src/Counter.sol.
Configure for Zroarus#
Pin the EVM version to cancun. Solidity 0.8.30 and later default to Prague, which the Testnet does not run, so contracts compiled with the default can fail to deploy or behave differently.
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.28"
evm_version = "cancun"
[rpc_endpoints]
zroarus_testnet = "https://rpc.testnet.zroarus.com"Deploy#
Load your test key into the current shell session only. It is never written to a file or to your shell history.
read -rs ZROARUS_TESTNET_KEY && export ZROARUS_TESTNET_KEY # paste, then Enter
forge create src/Counter.sol:Counter \
--rpc-url zroarus_testnet \
--private-key "$ZROARUS_TESTNET_KEY" \
--broadcastThe output includes Deployed to and Transaction hash. Paste either into the explorer(opens in a new tab) search. The transaction is final as soon as it is in a block.
Interact#
CONTRACT=0xYourDeployedAddress
cast call "$CONTRACT" "number()(uint256)" --rpc-url zroarus_testnet
cast send "$CONTRACT" "increment()" --rpc-url zroarus_testnet --private-key "$ZROARUS_TESTNET_KEY"
cast call "$CONTRACT" "number()(uint256)" --rpc-url zroarus_testnet
unset ZROARUS_TESTNET_KEYScripted deployments#
Because the Testnet can be reset, keep deployments in a script so you can redeploy everything with one command.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {Script} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
contract Deploy is Script {
function run() external {
vm.startBroadcast();
new Counter();
vm.stopBroadcast();
}
}forge script script/Deploy.s.sol:Deploy \
--rpc-url zroarus_testnet \
--private-key "$ZROARUS_TESTNET_KEY" \
--broadcastSomething wrong or missing on this page? Send developer feedback.