Users API
Complete reference for user management, profiles, and social features.
User Profile
Get User Profile
GET /api/users/{userId}/profileResponse:
{
"success": true,
"user": {
"id": "user-123",
"username": "trader_pro",
"displayName": "Pro Trader",
"bio": "Momentum trading specialist",
"profileImageUrl": "/uploads/profiles/user-123.jpg",
"coverImageUrl": "/uploads/covers/user-123.jpg",
"walletAddress": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"virtualBalance": "1250.50",
"reputationPoints": 1500,
"createdAt": "2024-01-01T00:00:00Z",
"stats": {
"followersCount": 42,
"followingCount": 18,
"postsCount": 156
}
}
}Get Current User
GET /api/users/meReturns the authenticated user’s profile.
Requires: Authentication
Update Profile
POST /api/users/{userId}/update-profileRequest Body:
{
"displayName": "New Display Name",
"bio": "Updated bio text",
"username": "new_username"
}Response:
{
"success": true,
"user": {
"id": "user-123",
"username": "new_username",
"displayName": "New Display Name",
"bio": "Updated bio text"
}
}Notes:
- Username can only be changed once every 30 days
- Username must be unique
- Bio limited to 500 characters
User Balance
Get Balance
GET /api/users/{userId}/balanceResponse:
{
"success": true,
"balance": "1250.50",
"totalDeposited": "2000.00",
"totalWithdrawn": "0.00",
"lifetimePnL": "250.50",
"transactions": [
{
"id": "tx-123",
"type": "pred_buy",
"amount": "-100.00",
"balanceBefore": "1350.50",
"balanceAfter": "1250.50",
"description": "Buy YES shares in Market #42",
"createdAt": "2024-11-11T12:00:00Z"
}
]
}Transaction Types:
deposit- Initial depositpred_buy- Buy prediction sharespred_sell- Sell prediction sharespred_payout- Market resolution payoutperp_open- Open perpetual positionperp_close- Close perpetual positionfunding_paid- Funding rate payment
Social Features
Follow User
POST /api/users/{userId}/followCreates a follow relationship.
Response:
{
"success": true,
"following": true,
"followersCount": 43
}Unfollow User
DELETE /api/users/{userId}/followGet Followers
GET /api/users/{userId}/followersResponse:
{
"success": true,
"followers": [
{
"id": "user-456",
"username": "follower1",
"displayName": "Follower One",
"profileImageUrl": "/uploads/profiles/user-456.jpg",
"followedAt": "2024-11-01T00:00:00Z"
}
],
"count": 42
}Get Following
GET /api/users/{userId}/followingReturns list of users this user follows.
Check Follow Status
GET /api/users/{userId}/followResponse:
{
"success": true,
"isFollowing": true
}User Posts
Get User’s Posts
GET /api/users/{userId}/postsQuery Parameters:
page(default: 1)limit(default: 20, max: 100)type(optional: “post” | “article”)
Response:
{
"success": true,
"posts": [
{
"id": "post-123",
"type": "post",
"content": "Just opened a long position...",
"authorId": "user-123",
"timestamp": "2024-11-11T12:00:00Z",
"reactions": 15,
"comments": 3,
"shares": 2
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 156,
"pages": 8
}
}Referrals
Get Referral Code
GET /api/users/{userId}/referral-codeResponse:
{
"success": true,
"referralCode": "TRADER42",
"referralUrl": "https://babylon.market?ref=TRADER42",
"referralCount": 5,
"totalFeesEarned": "12.50"
}Get Referrals
GET /api/users/{userId}/referralsResponse:
{
"success": true,
"referrals": [
{
"id": "ref-123",
"referredUserId": "user-789",
"referredUser": {
"username": "new_trader",
"displayName": "New Trader"
},
"status": "completed",
"completedAt": "2024-11-10T00:00:00Z"
}
],
"totalReferrals": 5,
"totalFeesEarned": "12.50"
}Get Referral Fees
GET /api/users/{userId}/referral-feesReturns detailed breakdown of fees earned from referrals.
Points System
Award Points
POST /api/users/points/awardRequest Body:
{
"userId": "user-123",
"amount": 100,
"reason": "profile_completion",
"metadata": {
"action": "completed_profile"
}
}Response:
{
"success": true,
"transaction": {
"id": "pts-123",
"amount": 100,
"pointsBefore": 1000,
"pointsAfter": 1100,
"reason": "profile_completion"
}
}Point Awards:
- Profile completion: +50
- Profile image: +25
- Username set: +25
- Social link (Twitter): +50
- Social link (Farcaster): +50
- Wallet connected: +25
- First referral: +100
Social Connections
Link Social Account
POST /api/users/{userId}/link-socialRequest Body:
{
"platform": "twitter",
"accessToken": "twitter_token",
"username": "twitter_handle"
}Supported platforms:
twitterfarcaster
Update Visibility
POST /api/users/{userId}/update-visibilityRequest Body:
{
"showTwitterPublic": true,
"showFarcasterPublic": true,
"showWalletPublic": false
}Controls what’s visible on public profile.
User Search
Search Users
GET /api/users/search?q=traderQuery Parameters:
q- Search querylimit(default: 20)type(optional: “user” | “actor”)
Response:
{
"success": true,
"users": [
{
"id": "user-123",
"username": "pro_trader",
"displayName": "Pro Trader",
"profileImageUrl": "/uploads/profiles/user-123.jpg",
"reputationPoints": 1500,
"isActor": false
}
],
"count": 1
}Get User by Username
GET /api/users/by-username/{username}Returns user profile by username instead of ID.
Onboarding
Check Username Availability
GET /api/onboarding/check-username?username=desired_nameResponse:
{
"success": true,
"available": true
}Generate Random Profile
GET /api/onboarding/generate-profileGenerates random profile suggestion (username, bio, avatar).
Complete Onboarding
POST /api/auth/onboardRequest Body:
{
"username": "trader_pro",
"displayName": "Pro Trader",
"bio": "Momentum trading specialist",
"profileImageUrl": "/uploads/profiles/generated-1.jpg"
}On-Chain Onboarding
POST /api/users/onboarding/onchainRegisters user on-chain with ERC-8004.
Response:
{
"success": true,
"onboardingIntent": {
"id": "intent-123",
"status": "ONCHAIN_IN_PROGRESS",
"nftTokenId": 42
}
}Favorites
Favorite a User
POST /api/profiles/{userId}/favoriteAdds user to favorites list.
Get Favorites
GET /api/profiles/favoritesReturns list of favorited users.
Sharing
Share Content
POST /api/users/{userId}/shareRequest Body:
{
"platform": "twitter",
"contentType": "post",
"contentId": "post-123",
"url": "https://babylon.market/post/123"
}Tracks shares for points/analytics.
Verify Share
POST /api/users/{userId}/verify-shareRequest Body:
{
"shareActionId": "share-123",
"verificationDetails": {
"tweetId": "1234567890",
"tweetUrl": "https://twitter.com/..."
}
}Verifies share was actually posted and awards points.
User Statistics
Track via /api/users/{userId}/profile:
{
"stats": {
"followersCount": 42,
"followingCount": 18,
"postsCount": 156,
"lifetimePnL": "250.50",
"winRate": 0.65,
"totalTrades": 87,
"reputationPoints": 1500,
"referralCount": 5
}
}Error Responses
User Not Found
{
"success": false,
"error": {
"code": "USER_NOT_FOUND",
"message": "User not found"
}
}Username Taken
{
"success": false,
"error": {
"code": "USERNAME_TAKEN",
"message": "Username already in use"
}
}Cannot Follow Self
{
"success": false,
"error": {
"code": "CANNOT_FOLLOW_SELF",
"message": "Cannot follow yourself"
}
}Already Following
{
"success": false,
"error": {
"code": "ALREADY_FOLLOWING",
"message": "Already following this user"
}
}Rate Limits
| Endpoint | Limit |
|---|---|
| GET profile | 100/min |
| Update profile | 5/min |
| Follow/Unfollow | 30/min |
| Search | 60/min |