Welcome to the official smart contract quickstart repository for the Devmatch Hackathon! This guide is designed to help you rapidly set up your smart contract development environment using Foundry, so you can focus on building, testing, and deploying your smart contracts during the hackathon.
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
- Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
- Chisel: Fast, utilitarian, and verbose solidity REPL.
$ forge build
$ forge test
$ forge fmt
$ forge snapshot
$ anvil
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ cast <subcommand>
$ forge --help
$ anvil --help
$ cast --help
src = "src"
: Specifies the directory where the source code (Solidity contracts) is located.out = "out"
: Specifies the directory where the compiled contract artifacts (e.g., ABI and bytecode) will be stored.libs = ["lib"]
: Defines the directory where external libraries (e.g., OpenZeppelin contracts) are stored.solc = "0.8.23"
: Sets the Solidity compiler version to0.8.23
. This ensures that all contracts are compiled with the same, specific version of the Solidity compiler.solc-optimizer = true
: Enables the Solidity compiler optimizer. This can help reduce gas costs by optimizing the compiled bytecode.solc-optimizer-runs = 200
: Sets the number of optimization runs.200
is a common setting for a good balance between bytecode size and gas efficiency.viaIR = true
: Enables the use of the intermediate representation (IR) pipeline in Solidity. This can provide better optimization results.
@openzeppelin/=lib/openzeppelin-contracts/
: Maps imports that start with@openzeppelin/
to the local directorylib/openzeppelin-contracts/
. This allows the use of OpenZeppelin libraries easily.ds-test/=lib/forge-std/lib/ds-test/src/
: Mapsds-test/
to the directory where the DSTest library is located. DSTest is a testing framework included with Foundry.forge-std/=lib/forge-std/src/
: Mapsforge-std/
to the directory where the Forge Standard Library is located. This provides additional utilities for testing and scripting in Foundry.
- Etherscan Configuration: These entries provide API keys and URLs for contract verification on blockchain explorers:
534351
: Custom Etherscan API entry for the Scroll Sepolia blockchain.17000
: Custom Etherscan API entry for the Ethereum Holesky blockchain.11155111
: Custom Etherscan API entry for the Ethereum Sepolia blockchain.
These API keys are used to automatically verify your contracts on the specified blockchain explorer after deployment, making it easier to interact with and audit your deployed contracts.
This project includes a .env.template
file that is crucial for managing environment variables required for deploying and interacting with your smart contracts. Below is an explanation of the variables defined in this file and how to use it:
-
Copy the Template: Start by making a copy of the
.env.template
file and rename it to.env
.cp .env.template .env
-
Set your keys: The
PRIV_KEY
is the private key for the Ethereum account you will use to deploy your contracts. Never share this key publicly and ensure this file is added to your.gitignore
to avoid committing it to version control. -
Configure RPC URLs: You need to set the RPC URLs for the Ethereum networks you plan to deploy to. For example, this template includes URLs for Scroll and Sepolia testnets.
SCROLL_RPC_URL="https://sepolia-rpc.scroll.io/" SEPOLIA_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/{YOUR_API_KEY}"
Replace {YOUR_API_KEY} in
SEPOLIA_RPC_URL
with your actual API key that you can get from Alchemy or Infura or any other RPC provider. -
Set Etherscan API Keys: These keys are used to verify your smart contracts on the respective blockchains. This template includes placeholders for Etherscan and ScrollScan API keys.
Sample command to run the deploy script:
$ forge script script/MultiSig.s.sol --rpc-url $SCROLL_RPC_URL --etherscan-api-key scroll-sepolia --broadcast --verify -vvvv