The Crypto Coin Flip Game is a decentralized web application that allows users to engage in a coin flip game using cryptocurrency on the Ethereum blockchain. Users can connect their wallets, place bets, and potentially double their cryptocurrency if they win the coin flip. The game is currently deployed on the Sepolia testnet.
- Blockchain Support: Users can select Ethereum sepolia Testnet Currency to place bet.
- Real-Time Betting: Place bets and see the outcome in real-time.
- Secure Transactions: All transactions are securely processed via smart contracts.
- Decentralized: The game is fully decentralized, with all transactions and outcomes recorded on the blockchain.
- Testnet Integration: Use testnet tokens (e.g., SepoliaETH) to play without risking real cryptocurrency.
- Frontend: React.js (using Vite), Styled-components
- Backend: Node.js, Web3.js / Ethers.js
- Smart Contracts: Solidity, Hardhat for development, Alchemy for deployment
- Blockchain: Ethereum (Sepolia testnet)
- Hosting: Vercel
- Node.js & npm installed
- MetaMask extension installed
- Alchemy API key (for interacting with the Ethereum blockchain)
- Sepolia testnet ETH (for placing bets)
git clone https://github.com/Vaibhav-Pant/CryptoCoinGame.git
cd crypto-coin-flip-game
npm install
Create a .env
file in the root directory and add the following:
VITE_CONTRACT_ADDRESS=your-contract-address
VITE_ETHERSCAN_API_KEY=your-etherscan-api-key
VITE_PRIVATE_KEY=your-private-key
VITE_SEPOLIA_URL=your-alchemy-api-key
To start the project locally:
npm run dev
This will run the Vite development server. Open http://localhost:3000 to view it in the browser.
To deploy the smart contract to the Sepolia testnet:
-
Navigate to the
hardhat
directory:cd hardhat
-
Deploy the contract:
npx hardhat run scripts/deploy.js --network sepolia
You can test the smart contract with Hardhat:
npx hardhat test
- Connect Your Wallet: Click the "Connect Wallet" button on the homepage.
- Check Balance: Ensure you have SepoliaETH in your wallet.
- Place Your Bet: Choose the amount you want to bet and select either "Heads" or "Tails".
- Flip the Coin: Confirm the transaction in MetaMask and wait for the result.
- Win or Lose: If you win, your wallet will automatically receive double the bet amount.
- Language: Solidity
- Network: Sepolia testnet
- Functionality:
placeBet(uint amount, bool guess)
: Places a bet and flips the coin.checkWin()
: Checks if the user has won the bet.withdraw()
: Allows the owner to withdraw funds from the contract.
- Transaction Not Visible in MetaMask: Internal transactions might not appear in MetaMask but can be seen on Etherscan.
- Insufficient Balance: Ensure you have enough SepoliaETH for placing a bet.
- Contract Deployment Issues: Double-check your Alchemy API key and network settings.
Contributions are welcome! Please fork this repository, create a new branch, and submit a pull request.
For questions, feel free to open an issue.