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.
- 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
- Users can propose partnerships with other learners
- Bidirectional confirmation system ensures mutual agreement
- Tracks partnership creation date and active status
- Prevents duplicate partnerships
- 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
- Mark sessions as completed
- Bidirectional 5-star rating system for both participants
- Records feedback for accountability and quality assurance
- Ratings are immutable once recorded
- Activate or deactivate accounts as needed
- All user data remains intact when inactive
- Users can reactivate accounts anytime
| 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 |
| 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) |
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
``` 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 } ```
session-counter: Auto-incrementing session ID counter
- 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
map-get?: Safe key-value retrievalmap-set: Data storageis-eq: Comparisonsis-none/is-some: Optional value checksmerge: Data structure updatesblock-height: Session timingvar-get/var-set: Session counter management
- Stacks CLI installed
- Testnet or Mainnet wallet with STX balance
- Clarity contract deployment rights
```bash stacks-cli contract deploy language-exchange.clar --testnet ```
;; 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)