Environment Preparation
Prerequisites
Required Tools
- Solidity ^0.8.18
- Primary smart contract programming language
- Ensures compatibility with latest EVM features
- Foundry Toolkit
forge
: Development, testing, and deploymentcast
: Contract interaction and network data readinganvil
: Local Ethereum node
Optional VSCode Plugins
- Hardhat Solidity Plugin
- Enhanced Solidity development features
- Auto-completion and code snippets
- Coverage Gutters
- Visualize code coverage in editor
- Highlight tested/untested paths
Local Development Setup
- Install Dependencies
npm install && forge install
This command installs:
- Node.js packages for development tasks
- Foundry dependencies for smart contract operations
Build & Deploy Process
1. Build Contracts
forge build
- Compiles all Solidity contracts
- Generates necessary artifacts (ABI, bytecode)
- Uses specified solc version
2. Run Tests
forge test -vvv
vvv
flag increases output verbosity- Shows detailed test information
- Displays gas usage
- Can use up to 5 v's for maximum verbosity
3. Deployment Process
Prerequisites
- Network RPC URL
- Target network: Base Sepolia testnet (for testnet phase)
- Deployer Account Setup
- Export private key in terminal
- Fund account with test ETH
- For Base Sepolia: Use Alchemy's testnet faucet
Deploy Command
forge script script/Deploy.s.sol --broadcast --rpc-url <your_rpc_url> --private-key $PRIVATE_KEY
4. Contract Verification
Setup
- Export Etherscan API key:
export ETHERSCAN_API_KEY=your_api_key
Verify Command
forge verify-contract <0x_contract_address> ContractName --watch --chain-id <chain_id>
Important Notes
- Optional: Use
-constructor-args
for contracts with constructor parameters - Base Sepolia chain ID: 84532
- Parameters must be ABI-encoded format
Tips & Troubleshooting
- Ensure sufficient funds in deployer account for gas fees
- Double-check network RPC URL before deployment
- Verify contract source code matches deployed bytecode
- Keep private keys secure and never commit them to version control