Skip to content

ShivRaiGithub/Raid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ‰ Raid the Chain

Cooperative on-chain boss raid game built on OneChain ยท OneHack 3.0 submission

Players pick a role (Knight / Mage / Assassin), attack a global monster once per cooldown, and earn proportional token rewards when the boss dies. The player who lands the final blow gets a 1.5ร— bonus. Every attack has a 15% chance to drop a weapon NFT.


๐Ÿ—‚ Project Structure

raid-the-chain/
โ”œโ”€โ”€ contract/                  # Move smart contract
โ”‚   โ”œโ”€โ”€ Move.toml
โ”‚   โ””โ”€โ”€ sources/
โ”‚       โ””โ”€โ”€ raid.move          # Core game logic
โ”œโ”€โ”€ frontend/                  # Next.js app
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ app/               # Next.js App Router
โ”‚   โ”‚   โ”œโ”€โ”€ components/        # UI components
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/             # useGameState hook
โ”‚   โ”‚   โ””โ”€โ”€ lib/               # onechain.ts, config.ts
โ”‚   โ”œโ”€โ”€ .env.example
โ”‚   โ””โ”€โ”€ package.json
โ””โ”€โ”€ deploy.sh                  # One-command deploy script

โš™๏ธ Prerequisites

Install these before anything else:

Tool Version Install
Node.js โ‰ฅ 18 https://nodejs.org
one CLI latest https://docs.onelabs.cc
Git any https://git-scm.com

Install the one CLI

# The one CLI is OneChain's fork of the sui CLI
# Install from OneChain docs or via cargo:
cargo install --git https://github.com/one-chain-labs/onechain one --bin one

# Verify
one --version

๐Ÿš€ Step-by-Step Setup

Step 1 โ€” Clone / set up project

# If you cloned from GitHub:
git clone https://github.com/YOUR_USERNAME/raid-the-chain.git
cd raid-the-chain

# Or just navigate to the project folder:
cd raid-the-chain

Step 2 โ€” Set up OneChain wallet

# Create a new wallet address
one client new-address ed25519

# Check your address
one client active-address

# Switch to testnet
one client switch --env testnet

# If testnet isn't configured yet, add it:
one client new-env --alias testnet --rpc https://rpc-testnet.onelabs.cc:443

# Get testnet tokens from faucet
one client faucet --url https://faucet-testnet.onelabs.cc/gas

# Check balance
one client balance

Step 3 โ€” Build the Move contract

cd contract

# Build (checks for errors)
one move build

# Optional: run tests
one move test

Expected output:

BUILDING raid_the_chain
Build Successful

Step 4 โ€” Deploy the contract (Option A: Auto script)

# From the project root:
cd ..
chmod +x deploy.sh
./deploy.sh

The script will:

  1. Build the contract
  2. Publish to testnet
  3. Extract Package ID and GameState ID
  4. Spawn the first monster ("The Shadow Dragon", 10,000 HP)
  5. Write your frontend/.env.local automatically

Step 4 โ€” Deploy the contract (Option B: Manual)

cd contract

# Publish
one client publish \
  --network testnet \
  --gas-budget 100000000

# Note the output โ€” you'll see something like:
# ----- Transaction Effects ----
# Created Objects:
#   ID: 0xABC...  (Package โ€” Immutable)
#   ID: 0xDEF...  (GameState โ€” Shared)
#   ID: 0x123...  (AdminCap โ€” Owned by you)

Then spawn a monster:

one client call \
  --package <PACKAGE_ID> \
  --module raid \
  --function spawn_monster \
  --args \
    <ADMIN_CAP_ID> \
    <GAME_STATE_ID> \
    '"The Shadow Dragon"' \
    10000 \
    0 \
    0x6 \
  --gas-budget 50000000

The output will contain a new Shared object โ€” that's your Monster ID.

Then create frontend/.env.local:

NEXT_PUBLIC_PACKAGE_ID=0xYOUR_PACKAGE_ID
NEXT_PUBLIC_GAME_STATE_ID=0xYOUR_GAME_STATE_ID
NEXT_PUBLIC_MONSTER_ID=0xYOUR_MONSTER_ID

Step 5 โ€” Run the frontend

cd frontend

# Install dependencies
npm install

# Start dev server
npm run dev

Open http://localhost:3000 ๐ŸŽ‰


๐ŸŽฎ Gameplay

  1. Connect your OneWallet
  2. Pick a role โ€” permanent choice:
    • ๐Ÿ›ก๏ธ Knight โ€” 10 DMG, 2h cooldown (attacks ~12ร—/day)
    • ๐Ÿ”ฎ Mage โ€” 25 DMG, 6h cooldown (attacks ~4ร—/day)
    • ๐Ÿ—ก๏ธ Assassin โ€” 50 DMG, 12h cooldown (attacks ~2ร—/day)
  3. Attack the boss when your cooldown expires
  4. Watch the HP bar drain as the community raids together
  5. Land the final blow for a 1.5ร— reward bonus
  6. Collect rewards proportional to your damage contribution
  7. Loot chance: every attack has 15% chance to drop a weapon NFT

๐Ÿช™ Economy

Reward Who gets it
80% of pool All contributors, proportional to damage
20% of pool Top 10 damage dealers, split equally
1.5ร— multiplier Final blow player (on their proportional share)
Weapon NFT Random 15% drop on any attack

Weapon tiers

Tier Name Bonus
Common Iron Sword +5 DMG
Rare Silver Blade +15 DMG
Epic Dragon Fang +30 DMG

๐Ÿ”— OneChain Integration

Product Usage File
OneWallet Login + transaction signing for all game actions Providers.tsx
OneTransfer transfer::public_transfer distributes OCT rewards proportionally to every raider on monster death raid.move โ†’ distribute_rewards()
OnePlay Real-time on-chain leaderboard โ€” queries AttackLanded events directly from chain, aggregates damage per address, shows live rankings integrations.ts โ†’ fetchOnePlayLeaderboard()
OneID Resolves wallet addresses to human display names in leaderboard rows and the player stats bar. Falls back to short address if no profile. integrations.ts โ†’ resolveOneID()
OneDEX Each weapon NFT in your inventory has a "List on OneDEX โ†—" button that deep-links to OneDEX pre-filled with the weapon object. Collection view link also shown. integrations.ts โ†’ buildListWeaponOnDEXLink()

๐Ÿ›  Admin Commands (post-deploy)

Spawn a new monster after one is defeated:

one client call \
  --package <PACKAGE_ID> \
  --module raid \
  --function spawn_monster \
  --args <ADMIN_CAP_ID> <GAME_STATE_ID> '"Boss Name"' <HP> 0 0x6 \
  --gas-budget 50000000

Mint a weapon for a player (for testing):

one client call \
  --package <PACKAGE_ID> \
  --module raid \
  --function craft_weapon \
  --args <ADMIN_CAP_ID> <RECIPIENT_ADDRESS> 3 \
  --gas-budget 20000000
# tier: 1=Common, 2=Rare, 3=Epic

๐Ÿ” View on Chain


๐Ÿ— Production Build

cd frontend
npm run build
npm start

๐Ÿ› Troubleshooting

one: command not found โ†’ Install the one CLI from OneChain docs.

E_ALREADY_REGISTERED error โ†’ Your wallet is already registered. Just play!

E_COOLDOWN_ACTIVE error โ†’ Your attack cooldown hasn't expired. Check the timer in the UI.

Blank frontend / "no monster" โ†’ Double-check your .env.local IDs. Run one client object <MONSTER_ID> to verify the object exists.

Transaction fails with "insufficient gas" โ†’ Get more testnet tokens: one client faucet --url https://faucet-testnet.onelabs.cc/gas


Built with โค๏ธ for OneHack 3.0 on OneChain

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors