Skip to content

kateemmanuel347/Language-Learning-Partner-Exchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Language Learning Partner Exchange - Clarity Smart Contract

Overview

The Language Learning Partner Exchange is a decentralized smart contract built on the Stacks blockchain using Clarity. It enables language learners to find partners, schedule exchange sessions, track progress, and maintain transparent records of their learning partnerships—all secured by blockchain technology.

Key Features

1. User Registration

  • Users register with their preferred language to learn and their proficiency level
  • Stores user profile including learning language, proficiency (1-5), and account status
  • Each user is uniquely identified by their Stacks principal address

2. Partnership Matching

  • Users can propose partnerships with other learners
  • Bidirectional confirmation system ensures mutual agreement
  • Tracks partnership creation date and active status
  • Prevents duplicate partnerships

3. Session Scheduling

  • Create learning sessions with specific dates and durations
  • Sessions include language being learned, start block height, and duration
  • Automatic session ID generation for tracking
  • Supports both synchronous and asynchronous learning arrangements

4. Session Completion & Rating

  • Mark sessions as completed
  • Bidirectional 5-star rating system for both participants
  • Records feedback for accountability and quality assurance
  • Ratings are immutable once recorded

5. Account Management

  • Activate or deactivate accounts as needed
  • All user data remains intact when inactive
  • Users can reactivate accounts anytime

Smart Contract Functions

Public Write Functions

Function Parameters Purpose
register-user language, proficiency Create user account with language preference
deactivate-account None Deactivate user account temporarily
create-partnership partner, language Propose partnership with another user
schedule-session partner, language, duration Schedule learning session
complete-session session-id, rating Mark session complete and rate partner

Read-Only Query Functions

Function Parameters Purpose
get-user-info user Retrieve user profile data
get-partnership-status user1, user2 Check partnership status
get-session-details session-id View session information
get-user-statistics user Get user stats (sessions, avg rating)

Error Handling

The contract implements robust error management with 5 distinct error codes:

  • Error 1: User already registered
  • Error 2: User not found
  • Error 3: Partnership already exists
  • Error 4: Session not found
  • Error 5: Unauthorized access

Data Structures

Maps (Data Storage)

``` users: { principal → {language, proficiency, active} } partnerships: { {user1, user2, language} → {created-at, active} } sessions: { session-id → {user1, user2, language, start-block, duration} } ratings: { {session-id, rater} → rating-score } ```

Variables

  • session-counter: Auto-incrementing session ID counter

Technical Implementation

Built with Clarity Best Practices

  • Input Validation: All function parameters validated before execution
  • Error Handling: Comprehensive error codes for different failure scenarios
  • Access Control: Principal-based authorization using tx-sender
  • Data Integrity: Immutable records using map-based storage
  • Efficient Queries: Read-only functions for safe data retrieval
  • Gas Optimization: Minimal state changes per transaction

Clarity Built-in Functions Used

  • map-get?: Safe key-value retrieval
  • map-set: Data storage
  • is-eq: Comparisons
  • is-none/is-some: Optional value checks
  • merge: Data structure updates
  • block-height: Session timing
  • var-get/var-set: Session counter management

Deployment

Prerequisites

  • Stacks CLI installed
  • Testnet or Mainnet wallet with STX balance
  • Clarity contract deployment rights

Deploy Command

```bash stacks-cli contract deploy language-exchange.clar --testnet ```

Usage Example

;; 1. Register as a user
(contract-call? .language-exchange register-user "Spanish" u4)

;; 2. View user profile
(contract-call? .language-exchange get-user-info tx-sender)

;; 3. Create partnership
(contract-call? .language-exchange create-partnership 'ST1234... "Spanish")

;; 4. Schedule session
(contract-call? .language-exchange schedule-session 'ST1234... "Spanish" u60)

;; 5. Complete and rate
(contract-call? .language-exchange complete-session u1 u5)

About

The Language Learning Partner Exchange is a decentralized smart contract built on the Stacks blockchain using Clarity. It enables users to find language learning partners, schedule exchange sessions, and rate their learning experiences.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors