This is a learning project that implements a simple calculator contract using Solidity. The project demonstrates various concepts including:
- Custom value types using
typein Solidity - Basic arithmetic operations
- Event emissions
- State management
- Testing with both Foundry and Hardhat
The project follows a hybrid structure that works with both Foundry and Hardhat:
├── src/ # Solidity source files
│ ├── Calc.sol # Main calculator contract
│ └── CalcParamLib.sol # Library for calcParam type
├── test/ # Test files
│ ├── Calc.t.sol # Foundry tests
│ └── Calc.t.js # Hardhat tests
├── script/ # Deployment scripts
│ └── deploy-arbitrum-sepolia.js
└── foundry.toml # Foundry configuration
- Custom Value Type: Uses
calcParamtype for calculations - Basic Operations: Addition, subtraction, multiplication, and division
- Error Handling: Division by zero protection
- Event Tracking: Emits events for all operations
- Result Storage: Keeps track of the latest result per address
-
Clone the repository
-
Install dependencies:
npm install
-
Create a
.envfile in the project root with the following variables:PRIVATE_KEY=your_private_key_here ARBISCAN_API_KEY=your_arbiscan_api_key_here
npx hardhat testforge testThe project includes deployment scripts for the Arbitrum Sepolia testnet:
-
Deploy the contract:
npx hardhat run script/deploy-arbitrum-sepolia.js --network arbitrumSepolia
-
Verify the contract on Arbiscan:
npx hardhat verify --network arbitrumSepolia <deployed_contract_address>
- Hardhat: Main development framework
- Foundry: Used for Solidity testing
- @nomicfoundation/hardhat-foundry: Plugin to integrate Hardhat with Foundry's project structure
- Arbitrum Sepolia: Test network for deployment