Chemical

Multiplayer on-chain chain-reaction game on Hedera with fixed bets and winner NFTs.

Chemical

Created At

ETHOnline 2025

Project Description

Chain Hedera: https://chainlist.org/chain/296

chain add https://portal.hedera.com/faucet

faucet https://hashscan.io/testnet/contract/0x099cdd44a061C7875B525f74737E77Dc1e311014 https://hashscan.io/testnet/contract/0x52619a44887a9370Acdce3BDee82122320550200

Chemical Chain Reaction is a fast, on-chain multiplayer strategy game on Hedera where 2–8 players join a room, place a fixed 0.0001 ETH-equivalent bet on the EVM, and battle on a classic chain-reaction board until one player remains; the pot is paid on-chain to the winner and an ERC721 achievement NFT is minted. The system uses two Solidity contracts—ChemicalGame for lifecycle, escrow, payouts, and admin finish; and ChemicalNFT for minting winner NFTs—integrated with a Next.js frontend, Socket.IO real-time updates, and Prisma for off-chain indexing and verification. Built for low latency and finality on Hedera’s EVM via the JSON‑RPC relay, it enforces strict bet validation, capped player slots, and safe withdrawals to keep gameplay predictable and secure.

How it's Made

Hedera + Hardhat: Contracts are written and deployed with Hardhat targeting Hedera’s EVM through the Hashio/Hiero JSON‑RPC Relay, using standard Ethereum tooling and Ethers.js for scripts and verification. Hardhat network config points to Hedera testnet RPC with an ECDSA account from the Hedera Developer Portal, enabling compile, test, and deploy flows similar to Ethereum networks.​

Smart contracts: ChemicalGame exposes createGame(string roomCode) and joinGame(string roomCode) with strict msg.value == 0.0001 ether checks, tracks up to 8 players in a fixed address for gas efficiency, escrows the pot, and provides admin-only finishGame to distribute 0.0001 ETH × playerCount to the winner; failed sends accrue to pendingWithdrawals for pull-based claims. ChemicalNFT is a minimal ERC721; ChemicalGame mints via mintAchievement with a metadata URI (e.g., IPFS), prevents duplicate claims per player, and omits burn to reduce surface area.​

App integration: Next.js UI collects only roomId and submits 0.0001 ETH for create/join using Ethers.js against Hedera’s RPC endpoint; a backend API triggers finishGame and NFT minting after server-side validation. Socket.IO broadcasts room and board state to clients in real time, while Prisma stores off-chain snapshots and a stateHash used to reconcile and verify front-end state against on-chain outcomes.​

Hedera specifics: Using the Hedera JSON‑RPC relay keeps the developer workflow identical to Ethereum (ABI, addresses, Ethers.js), while benefiting from Hedera’s fast finality for timely game settlements; Hardhat v3 conventions and keystore helpers can be used for cleaner network and secret management.​

Key implementation notes

Deployment: Configure hardhat.config to include Hedera RPC and operator private key; run compile/build and deploy scripts as with any EVM chain; boilerplate repos and docs accelerate setup.​

Security: Ownable guards admin-only finish; ReentrancyGuard secures withdrawals; strict equality on msg.value prevents bet mismatch; a one‑hour timeout enables refunds for stalled rooms.​

DX and performance: Fixed-size arrays minimize storage ops; Ethers.js scripts integrate seamlessly with Hedera RPC; finality characteristics reduce waiting time for payout UX while preserving EVM compatibility for tooling.

background image mobile

Join the mailing list

Get the latest news and updates