A decentralized auction platform implementing a commit-reveal mechanism with a randomly determined end time using Chainlink VRF. Built with Foundry for smart contracts and React + Vite + Ethers.js for the optional frontend.
git clone https://github.com/your-username/candle-auction.git
cd candle-auction
# Install Foundry dependencies
forge install
# Install frontend dependencies
cd frontend
npm install
cd ..Create a .env in the root:
SEPOLIA_RPC_URL=<your Sepolia RPC URL>
PRIVATE_KEY=<deployer private key>
VRF_SUBSCRIPTION_ID=<Chainlink VRF v2 subscription ID>
LINK_TOKEN_ADDRESS=<>
VRF_COORDINATOR_ADDRESS=<>.
├── src/
│ └── CandleAuction.sol # Modified main contract
├── solscripts/ # Forge scripts for manual interactions
│ ├── CommitBid.s.sol
│ ├── RevealBid.s.sol
│ └── NextPhase.s.sol
| |__StartAuction.s.sol
├── script/ # Deployment scripts (Solidity)
│ ├── DeployCandleAuction.s.sol # Deploy core contract
│ └── DeployMocksAndAuction.s.sol # Deploy mocks + full auction locally
├── scripts/ # JS scripts for automation
│ ├── commit.js # Commit phase via ethers.js
│ └── reveal.js # Reveal phase via ethers.js
├── test/
│ └── CandleAuctionTest.t.sol # Expanded unit tests
├── frontend/
│ └── App.jsx # Modified React frontend
├── foundry.toml
└── .env
-
Start local node:
anvil
-
Deploy mocks and auction:
forge script \ script/DeployMocksAndAuction.s.sol \ --rpc-url http://127.0.0.1:8545 \ --private-key $PRIVATE_KEY \ --broadcast
Deploy core contract only:
forge script \
script/DeployCandleAuction.s.sol:DeployCandleAuction \
--rpc-url $SEPOLIA_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcastAfter deployment, update your frontend’s contract address if needed.
-
Commit phase:
forge script \ solscripts/CommitBid.s.sol:CommitBid \ --rpc-url $SEPOLIA_RPC_URL \ --private-key $PRIVATE_KEY \ --broadcast \ --args <contract> <bidHash> <value>
-
Reveal phase:
forge script \ solscripts/RevealBid.s.sol:RevealBid \ --rpc-url $SEPOLIA_RPC_URL \ --private-key $PRIVATE_KEY \ --broadcast \ --args <contract> <amount> <salt>
-
Advance phase:
forge script \ solscripts/NextPhase.s.sol:NextPhase \ --rpc-url $SEPOLIA_RPC_URL \ --private-key $PRIVATE_KEY \ --broadcast \ --args <contract>
In the root, run:
node scripts/commit.js \
--contract 0xYourAuctionAddress \
--amount 1.0 \
--salt 0xabc123 \
--rpc $SEPOLIA_RPC_URL \
--key $PRIVATE_KEY
node scripts/reveal.js \
--contract 0xYourAuctionAddress \
--amount 1.0 \
--salt 0xabc123 \
--rpc $SEPOLIA_RPC_URL \
--key $PRIVATE_KEYThese helpers wrap the ethers.js calls for commit and reveal.
Run all unit tests (including new edge-case tests) via Foundry:
forge test -vvvvTests cover:
- Bid commitment + reveal
- Incorrect salt or amount
- Phase gating
- VRF-driven random end timestamp
cd frontend
npm run devConnect MetaMask to Sepolia, input your contract address, and you’ll see buttons for:
- startAuction
- commitBid
- nextPhase
- revealBid
- requestRandomEndBlock
- settleAuction
- withdraw
-
Commit Phase
Users submitkeccak256(amount, salt)and lock ETH. -
Reveal Phase
Bidders open their bids with(amount, salt).
Highest valid bid before the random cutoff wins. -
Random End
Owner callsrequestRandomEndBlock().
Chainlink VRF supplies a random timestamp between deadlines. -
Settlement
After final phase, owner callssettleAuction()and bidders withdraw.
- Decentralized commit-reveal auction
- Confidential bids via hashing & salt
- Randomized reveal cutoff with Chainlink VRF
- Modular Forge scripts and JS automation
- Expanded unit tests for edge cases
- Minimal React UI for end-to-end demo
- CI integration for automated deploy + tests
- Enhanced frontend UX (timers, notifications)
- Gas-optimizations in scripts
- Mainnet deployment support
Shubh Bobade Reach out on LinkedIn | GitHub
This project is licensed under the MIT License.