Skip to content

goodnessalice/Decentralized-Game-Server-Hosting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Decentralized Game Server Hosting Smart Contract

A robust Clarity smart contract for peer-to-peer game server hosting on the Stacks blockchain. This contract enables users to host game servers, rent server capacity, and build a decentralized gaming infrastructure with built-in ratings and payments.

🎮 Overview

This smart contract creates a decentralized marketplace where:

  • Hosts can register and monetize their game servers
  • Renters can pay to use server capacity on-demand
  • Platform takes a configurable fee for facilitating transactions
  • Community can rate servers to ensure quality

🚀 Features

For Server Hosts

  • Register Servers: List your game server with custom pricing and capacity
  • Dynamic Pricing: Update server prices anytime
  • Status Management: Set servers to active, inactive, or maintenance mode
  • Earnings Tracking: Monitor total earnings from all rentals
  • Capacity Control: Define max players and total capacity slots

For Renters

  • Flexible Rentals: Rent server slots for custom durations (in blocks)
  • Slot-Based System: Reserve exactly the number of slots you need
  • Active Rental Management: End rentals early to free up capacity
  • Rating System: Rate servers (1-5 stars) after using them

Platform Features

  • Automated Payments: Instant payment splitting between host and platform
  • Fee Management: Configurable platform fee (max 20%)
  • Reputation System: Community-driven server ratings
  • Capacity Protection: Prevents overbooking with real-time tracking

📋 Contract Functions

Public Functions

register-server

(register-server (name (string-ascii 50)) (description (string-ascii 200)) 
                 (price-per-hour uint) (max-players uint) (total-capacity uint))

Register a new game server with pricing and capacity details.

Parameters:

  • name: Server name (1-50 characters)
  • description: Server description (1-200 characters)
  • price-per-hour: Price in microSTX per block
  • max-players: Maximum players per rental session
  • total-capacity: Total concurrent slots available

Returns: Server ID on success


rent-server

(rent-server (server-id uint) (duration-blocks uint) (slots uint))

Rent server capacity for a specified duration.

Parameters:

  • server-id: ID of the server to rent
  • duration-blocks: Rental duration (max 52,560 blocks ≈ 1 year)
  • slots: Number of player slots to reserve

Payment: Automatically transfers STX to contract, then to host (minus platform fee)

Returns: Rental ID on success


end-rental

(end-rental (rental-id uint))

Terminate an active rental and free up server capacity.

Only callable by: Original renter


rate-server

(rate-server (server-id uint) (rating uint))

Rate a server you've previously rented.

Parameters:

  • server-id: Server to rate
  • rating: 1-5 stars

Requirements:

  • Must have rented the server before
  • Can only rate once per server

update-server-status

(update-server-status (server-id uint) (new-status uint))

Change server status (active=1, inactive=2, maintenance=3).

Only callable by: Server host


update-server-price

(update-server-price (server-id uint) (new-price uint))

Update server rental price.

Only callable by: Server host


set-platform-fee

(set-platform-fee (new-fee uint))

Update platform fee percentage (max 20%).

Only callable by: Contract owner


withdraw-contract-balance

(withdraw-contract-balance)

Withdraw accumulated platform fees.

Only callable by: Contract owner


Read-Only Functions

get-server

(get-server (server-id uint))

Retrieve complete server information.


get-rental

(get-rental (rental-id uint))

Get rental details including dates and payment info.


get-server-rating

(get-server-rating (server-id uint))

Calculate average server rating.


get-host-earnings

(get-host-earnings (host principal))

Get total lifetime earnings for a host.


get-platform-fee

(get-platform-fee)

Get current platform fee percentage.


is-server-available

(is-server-available (server-id uint))

Check if server has available capacity.


💰 Payment Flow

  1. Renter calls rent-server with STX payment
  2. Contract receives full payment
  3. Platform fee calculated (default 5%)
  4. Host receives payment minus fee immediately
  5. Platform fee remains in contract for owner withdrawal

Example:

  • Rental cost: 1000 STX
  • Platform fee (5%): 50 STX
  • Host receives: 950 STX

🔒 Security Features

  • Input Validation: All user inputs validated before processing
  • Authorization Checks: Only authorized users can modify data
  • Capacity Protection: Prevents overbooking with real-time checks
  • Payment Safety: Atomic transfers with failure rollback
  • Rate Limiting: One rating per user per server
  • Bounds Checking: Duration and rating limits enforced

📊 Error Codes

Code Constant Description
u100 err-owner-only Only contract owner can perform action
u101 err-not-found Server or rental not found
u102 err-unauthorized Caller not authorized
u103 err-invalid-price Price must be greater than 0
u104 err-insufficient-funds Insufficient STX for rental
u105 err-server-inactive Server not active
u106 err-already-exists Resource already exists
u107 err-invalid-capacity Invalid capacity value
u108 err-server-full No available slots
u109 err-not-renter Must have rented to perform action
u110 err-already-rated Already rated this server
u111 err-invalid-duration Duration out of valid range
u112 err-invalid-rating Rating must be 1-5

🎯 Use Cases

1. Minecraft Server Hosting

Host registers Minecraft server with 20 player capacity, renters pay per block for slots.

2. CS:GO Tournament Hosting

Rent entire server capacity for tournament duration with guaranteed performance.

3. Community Gaming

Small communities rent affordable slots on shared servers with hourly billing.

4. Server Marketplace

Build a reputation-based marketplace where quality hosts earn premium pricing.

📐 Technical Specifications

  • Language: Clarity (Stacks Blockchain)
  • Lines of Code: 297
  • Max Duration: 52,560 blocks (~1 year)
  • Max Platform Fee: 20%
  • Rating Scale: 1-5 stars
  • String Limits: Name (50 chars), Description (200 chars)

🔧 Deployment

  1. Deploy contract to Stacks blockchain
  2. Contract deployer becomes owner with fee withdrawal rights
  3. Initial platform fee set to 5%
  4. Ready for hosts to register servers

📝 Best Practices

For Hosts

  • Set competitive pricing based on server specs
  • Maintain server status accurately
  • Respond to maintenance needs promptly
  • Build reputation through quality service

For Renters

  • Check server ratings before renting
  • Rent appropriate duration to avoid waste
  • Rate servers to help community
  • End rentals when done to free capacity

For Platform Operators

  • Keep platform fees reasonable (5-10%)
  • Monitor for malicious behavior
  • Regular balance withdrawals
  • Community engagement for trust

🚨 Limitations

  • No refund mechanism (rent responsibly)
  • Last-write-wins for concurrent updates
  • No server performance guarantees (off-chain)
  • Rating cannot be changed after submission
  • Duration paid upfront (no partial refunds)

About

This is a peer-to-peer marketplace built on the Stacks blockchain that enables game server owners to monetize their infrastructure while providing renters with transparent, on-demand access to gaming resources. The contract automates payments, manages capacity allocation, and maintains a reputation system—all without centralized intermediaries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors