"use client"; import { useEffect, useState } from "react"; import Web3 from "web3"; import Lobby from "./Lobby"; import Commit from "./Commit"; import Reveal from "./Reveal"; export default function Clash() { const [config, setConfig] = useState(null); const [web3, setWeb3] = useState(null); const [contract, setContract] = useState(null); const [account, setAccount] = useState(""); const [status, setStatus] = useState(""); // Inputs for contract functions const [phase, setPhase] = useState<"lobby" | "commit" | "reveal">("lobby"); // Clear status when phase changes useEffect(() => { setStatus(""); }, [phase]); // Load config and contract useEffect(() => { const loadConfig = async () => { try { const response = await fetch("/crypto_clash/config.json"); const data = await response.json(); setConfig(data); const web3Instance = new Web3(data.API_URL); setWeb3(web3Instance); const contractInstance = new web3Instance.eth.Contract( data.GAME_ABI, data.GAME_CONTRACT_ADDRESS ); setContract(contractInstance); // Get account if (globalThis.window !== undefined && (globalThis as any).ethereum) { try { const accounts = await (globalThis as any).ethereum.request({ method: "eth_requestAccounts", }); setAccount(accounts[0]); } catch (err: any) { setStatus( "MetaMask not available or user denied access: " + err.message ); } } } catch (err: any) { setStatus("Failed to load config: " + err.message); } }; loadConfig(); }, []); return (
Crypto Clash Logo

Crypto Clash

{phase === "lobby" && "Register for a game to start."} {phase === "commit" && "Commit your move."} {phase === "reveal" && "Reveal your move."}

Connected Account:{" "} {account ? `${account.slice(0, 6)}...${account.slice(-4)}` : "Not connected"}

Game Contract Address:{" "} {config?.GAME_CONTRACT_ADDRESS}

{phase === "lobby" && ( )} {phase === "commit" && ( )} {phase === "reveal" && ( )}
{status && (

{status}

)}

ℹ️ Note:

  • MetaMask or a compatible Web3 wallet is required for write operations
  • Use bytes32 for encrypted move (see contract docs for details)
  • ETH values are in Ether (not Wei)
); }