crosschain casino
Cross-chain casino dApp enabling seamless bets and payouts across multiple blockchains.
Problem Statement
Cross-Chain Casino is a decentralized gaming app that lets anyone place onchain bets from any supported chain and execute the wager on a destination chain in one click. It uses the Avail Nexus SDK to abstract bridging, routing, and execution so players don’t have to pre-move funds or switch networks. The result is a smooth, multi-chain casino experience with provable settlement and transparent game rules.What it doesLets a player stake native or ERC-20 assets on their source chain (e.g., ETH on Base) and automatically Bridge & Execute a bet against a game contract deployed on a destination chain (e.g., Polygon).Handles the bridge leg and the contract call atomically via Nexus intents, returning the outcome and funds without manual bridging.Pays winners instantly from the destination contract; optional post-win intent can auto-return winnings to the player’s origin chain.How it uses Avail Nexus SDKnexus-widgets powers wallet connection, cross-chain token selection, and a Bridge & Execute button for the betting flow.nexus-core (headless) can be used for advanced intents and safety rails (slippage ceilings, gas budgets, allowed routes).The app demonstrates a full cross-chain intent: sourceChain funds → bridge → execute placeBet(guess) on the destination contract → emit outcome → payout.Game mechanicsInitial game is Dice: player guesses 1–6 and stakes an amount; the destination contract computes a roll and pays out if the guess matches.House edge and payout ratios are configurable; transparency is enforced via open-source contracts and onchain events.For hackathon speed the demo uses simple block-derived randomness; roadmap includes Chainlink VRF or equivalent verifiable RNG.User flowConnect wallet, pick source chain, token, amount, and game guess.Click Bridge & Play; the Nexus intent bridges funds and executes the bet on the destination chain.The contract emits Bet events and immediately pays out on win; the UI shows status and transaction links.Why this is usefulRemoves the biggest UX friction in Web3 gaming: pre-bridging and chain switching.Unlocks unified liquidity: players can use assets where they already are.Provides a template for any multi-chain game or prediction market to go cross-chain with minimal extra code.
Solution
Cross-Chain Casino was built from the ground up using Vite + React + TypeScript for speed and modularity. We started with the official Avail Nexus Vite template, wiring in @avail-project/nexus-core and @avail-project/nexus-widgets to handle all cross-chain intents. The frontend uses Wagmi + Viem for wallet and chain connectivity and shadcn-style UI for a clean look.The core feature—placing a bet from one chain and executing it on another—runs through the Nexus SDK’s Bridge & Execute workflow. Inside React, we wrapped the SDK in a custom NexusProvider component that initializes the Wagmi config, Query Client, and the Nexus Provider. A dedicated BridgePlayButton component builds a full BridgeAndExecuteParams object that specifies source chain, destination chain, asset, and the function call to our game contract.On the smart-contract side, we deployed a minimal DiceGame.sol written in Solidity ^0.8.20. The contract uses pseudo-random block data to roll a number 1-6, emits a Bet event, and immediately pays out on correct guesses. It’s simple but ideal for demonstrating Avail’s cross-chain execution—bets bridged from any chain call placeBet on this contract.We kept the app lightweight:Frontend → Vite + React app hosted on Vercel.Blockchain layer → Any EVM chain (tested on Base ↔ Polygon) running the DiceGame contract.Cross-chain logic → Avail Nexus SDK handling all routing, gas abstraction, and execution.Hacky but fun bits:Used Nexus widgets’ internal hooks directly to preview transaction states and surface live bridge status.Faked a “unified balance” view by aggregating Wagmi useBalance across chains for demo impact.Added instant payout visualization by listening to the Bet event via Viem websockets.
Hackathon
ETHOnline 2025
2025
Contributors
- aliveevie
56 contributions