A robust Clarity smart contract for a decentralized moving service marketplace built on the Stacks blockchain. This contract enables movers to register their services, customers to book moves, and facilitates secure transactions with rating and review functionality.
The Moving Service Marketplace contract provides a complete platform for:
- Mover Registration: Service providers register with their service type and hourly rates
- Customer Management: Customers create profiles and book moving services
- Booking System: Full lifecycle management from creation to completion
- Payment Handling: Secure STX token transactions
- Rating System: 5-star rating system with weighted average calculations
- Service Quality: Track mover performance and customer satisfaction
- Register as a mover with service type and hourly rate
- Deactivate/reactivate mover status
- Track total jobs completed and average rating
- View mover profile information
- Register as a customer
- View booking history
- Track total bookings made
- Create bookings with specific movers
- Accept/reject bookings (mover action)
- Complete bookings after service delivery
- Cancel pending bookings (customer action)
- Automatic payment transfer on completion
- Rate completed bookings (1-5 stars)
- Leave detailed reviews
- Automatic rating aggregation
- Track mover reputation
``` { name: string, service-type: string, hourly-rate: uint (in microSTX), active: boolean, total-jobs: uint, total-rating: uint, rating-count: uint } ```
``` { name: string, total-bookings: uint } ```
``` { customer: principal, mover: principal, hours: uint, total-cost: uint, status: string (pending/accepted/completed/cancelled), created-at: uint (block height), rating: uint (0-5, 0 if not rated), review: string } ```
Register as a mover in the marketplace.
- Parameters:
name: Mover's business name (non-empty string)service-type: Type of moving service (non-empty string)hourly-rate: Rate in microSTX per hour (positive uint)
- Returns:
(ok true)on success - Errors:
ERR-ALREADY-REGISTERED,ERR-INVALID-INPUT
Deactivate your mover account.
- Returns:
(ok true)on success - Errors:
ERR-NOT-REGISTERED
Reactivate your mover account.
- Returns:
(ok true)on success - Errors:
ERR-NOT-REGISTERED
Register as a customer in the marketplace.
- Parameters:
name: Customer's name (non-empty string)
- Returns:
(ok true)on success - Errors:
ERR-ALREADY-REGISTERED,ERR-INVALID-INPUT
Create a new booking with a mover.
- Parameters:
mover: Principal address of the moverhours: Number of hours needed (positive uint)
- Returns:
(ok booking-id)on success - Errors:
ERR-NOT-REGISTERED,ERR-MOVER-NOT-FOUND,ERR-MOVER-INACTIVE,ERR-INVALID-INPUT
Accept a pending booking (mover action).
- Parameters:
booking-id: ID of the booking to accept
- Returns:
(ok true)on success - Errors:
ERR-BOOKING-NOT-FOUND,ERR-INVALID-STATUS,ERR-UNAUTHORIZED
Mark a booking as completed and transfer payment (mover action).
- Parameters:
booking-id: ID of the booking to complete
- Returns:
(ok true)on success - Errors:
ERR-BOOKING-NOT-FOUND,ERR-INVALID-STATUS,ERR-UNAUTHORIZED,ERR-INSUFFICIENT-BALANCE
Cancel a pending booking (customer action).
- Parameters:
booking-id: ID of the booking to cancel
- Returns:
(ok true)on success - Errors:
ERR-BOOKING-NOT-FOUND,ERR-INVALID-STATUS,ERR-UNAUTHORIZED
Rate and review a completed booking.
- Parameters:
booking-id: ID of the completed bookingrating: Rating from 1-5 starsreview: Review text (non-empty string)
- Returns:
(ok true)on success - Errors:
ERR-BOOKING-NOT-FOUND,ERR-INVALID-STATUS,ERR-UNAUTHORIZED,ERR-INVALID-INPUT
Retrieve mover profile information.
- Returns: Mover profile or
none
Retrieve customer profile information.
- Returns: Customer profile or
none
Retrieve booking details.
- Returns: Booking details or
none
Get average rating for a mover.
- Returns: Average rating (0-5) or
none
| Code | Name | Description |
|---|---|---|
| 401 | ERR-NOT-REGISTERED | User is not registered as mover or customer |
| 402 | ERR-INSUFFICIENT-BALANCE | Insufficient STX balance for payment |
| 403 | ERR-INVALID-INPUT | Invalid input parameters (empty strings, invalid amounts) |
| 404 | ERR-NOT-FOUND | Mover, customer, or booking not found |
| 405 | ERR-ALREADY-REGISTERED | User already registered |
| 406 | ERR-MOVER-NOT-FOUND | Specified mover not found |
| 407 | ERR-MOVER-INACTIVE | Mover is not active |
| 408 | ERR-BOOKING-NOT-FOUND | Booking not found |
| 409 | ERR-INVALID-STATUS | Booking status doesn't allow this action |
| 410 | ERR-UNAUTHORIZED | Caller not authorized for this action |
| 422 | ERR-INVALID-RATING | Rating must be between 1 and 5 |
;; 1. Mover registers
(contract-call? .moving-marketplace register-mover "FastMove Inc" "Local Moving" u50000000)
;; 2. Customer registers
(contract-call? .moving-marketplace register-customer "John Doe")
;; 3. Customer creates booking (3 hours)
(contract-call? .moving-marketplace create-booking 'SP2MFRYGWESM5YBPQWYGNUC6YNXNTQC23DP2QE5Q u3)
;; 4. Mover accepts booking
(contract-call? .moving-marketplace accept-booking u0)
;; 5. Mover completes booking (payment transferred)
(contract-call? .moving-marketplace complete-booking u0)
;; 6. Customer rates the service
(contract-call? .moving-marketplace rate-booking u0 u5 "Excellent service!")
;; 7. Check mover rating
(contract-call? .moving-marketplace get-mover-rating 'SP2MFRYGWESM5YBPQWYGNUC6YNXNTQC23DP2QE5Q)