SpiceTraders

Spice Traders: On-chain space trading game with mining, ship management & Uniswap V4 DEX integration

SpiceTraders

Created At

ETHGlobal New Delhi

Project Description

This project combines a comprehensive blockchain-based space trading game with DeFi infrastructure to create an immersive on-chain gaming experience. Players mine resources, manage fleets of NFT ships, and trade on planet-specific markets powered by Uniswap V4.

Core Gameplay:

  • Resource Mining System: Players mine 4 resource types (Metal, Sapho Juice, Water, Spice) across 5 unique planets using Pyth Entropy for verifiable randomness
  • Ship Management: Own and manage NFT ships with different classes, cargo capacities, and fuel systems
  • Interplanetary Travel: Navigate 3D space using spice as fuel, with travel costs based on actual distance calculations
  • Planet-Specific Trading: Trade resources on 20 unique trading pairs (4 resources × 5 planets) using Uniswap V4 AMM

Technical Innovation:

  • Uniswap V4 Integration: Custom hooks create planet-specific markets that promote arbitrage opportunities - players must physically travel to different planets to access their unique trading rates
  • Pyth Entropy Integration: Verifiable randomness for fair mining outcomes
  • Resource Wrapping: Seamless conversion between ERC1155 resources and ERC20 wrapped tokens for trading
  • Gas-Optimized Contracts: Packed structs and efficient state management

Smart Contract System:

  • World.sol: Planet management and travel cost calculations
  • Player.sol: Player state and ship management with packed structs for gas efficiency
  • Ships.sol: ERC721 ship NFTs with customizable attributes
  • Market.sol: Uniswap V4 integration with automatic token wrapping/unwrapping
  • Mining.sol: Pyth Entropy-powered resource extraction with planet-specific difficulty

Frontend Features:

  • Next.js 15 with TypeScript and Tailwind CSS
  • Real-time trading quotes and market data
  • Mobile-responsive UI with ConnectKit wallet integration
  • Fleet management interface with ship switching and refueling
  • Comprehensive HUD showing resources, location, and ship status

Economic Design:

  • Strategic resource management with spice as the primary fuel
  • Planet specialization creating unique trading opportunities
  • Ship fleet building with different classes for various playstyles
  • Sustainable tokenomics with supply caps and fee structures

The project demonstrates how advanced DeFi protocols can enhance gaming through verifiable randomness, decentralized trading, and location-based restrictions while maintaining engaging gameplay loops. It's deployed on Base mainnet with full Uniswap V4 integration.

How it's Made

This project uses Uniswap V4 for the decentralized trading infrastructure and Pyth Network for verifiable randomness in the mining system. The frontend is built with Next.js 15, TypeScript, and Tailwind CSS, while the smart contracts are developed using Foundry and Solidity. I integrated Uniswap V4's custom hooks to create planet-specific trading markets that require physical travel between planets to access different trading rates, promoting arbitrage opportunities. Pyth Entropy provides cryptographically secure randomness for fair resource mining outcomes across different planets. The project uses OpenZeppelin's audited contract libraries for security and implements gas-optimized packed structs for efficient on-chain storage. The trading system automatically wraps ERC1155 resources into ERC20 tokens for Uniswap compatibility and unwraps them back after trades, creating a seamless user experience between the gaming and DeFi layers.

background image mobile

Join the mailing list

Get the latest news and updates