Guess Contract
Overview
- Purpose and flow
Public Interfaces
- Methods list (view/change)
- Parameters and return types
Examples
- Sample calls (near-cli / JS)
Fill in actual ABI/interfaces.
Kim.Fun Smart Contract
A NEAR Protocol smart contract for a social platform that combines content posting with staking mechanics and guessing games.
Overview
The Kim.Fun platform consists of two main contracts:
- Main Contract (
src/): Handles content posting, admin verification, and staking mechanics
Architecture
Main Contract Features
- Content Posting: Users can create posts by paying a posting fee in KIM tokens
- Admin Verification: Admins can verify posts with correct answers for guessing games
- Staking System: Users can stake KIM tokens on posts (upvoting) with a 24-hour lockup period
- FT Integration: Supports KIM token transfers via
ft_on_transferfor posts and stakes
Token Economics(configurable)
- Posting Fee: 0.1 KIM tokens per post
- Stake Lockup: 24-hour lockup period for post stakes
- Game Credits: 0.01 KIM per credit, 10 credits per game
- Game Attempts: 2 guesses per game
Contract Interactions
Main Contract Methods
Creating Posts
# Transfer KIM tokens with message to create a post
near call $KIM_TOKEN_CONTRACT ft_transfer_call '{
"receiver_id": "$MAIN_CONTRACT",
"amount": "1000000",
"msg": "{\"type\": \"CreatePost\", \"data\": \"Your post content here\"}"
}' --accountId $USER_ACCOUNT --depositYocto 1
Staking on Posts
# Stake KIM tokens on a post (upvote)
near call $KIM_TOKEN_CONTRACT ft_transfer_call '{
"receiver_id": "$MAIN_CONTRACT",
"amount": "500000",
"msg": "{\"type\": \"Upvote\", \"post_id\": 1}"
}' --accountId $USER_ACCOUNT --depositYocto 1
Admin Verification
# Verify a post with correct answers
near call $MAIN_CONTRACT admin_verify_post '{
"post_id": 1,
"original": "male",
"current": "female"
}' --accountId $ADMIN_ACCOUNT
Game Contract Methods
Buying Credits
# Buy game credits with KIM tokens
near call $KIM_TOKEN_CONTRACT ft_transfer_call '{
"receiver_id": "$GAME_CONTRACT",
"amount": "100000",
"msg": "{\"type\": \"BuyCredits\"}"
}' --accountId $USER_ACCOUNT --depositYocto 1
Starting a Game
# Start a new guessing game
near call $GAME_CONTRACT start_game '{}' --accountId $USER_ACCOUNT
Making a Guess
# Make a guess in an active game
near call $GAME_CONTRACT make_guess '{
"game_id": 1,
"original": "male",
"current": "female"
}' --accountId $USER_ACCOUNT
View Functions
Main Contract
get_posts(from_index, limit): Get posts with paginationget_post(post_id): Get specific post detailsget_verified_posts(): Get all verified post IDsget_contract_info(): Get contract configuration
Game Contract
get_game(game_id): Get game detailsget_player_games(player): Get all games for a playerget_player_stats(player): Get player statisticsget_player_badges(player): Get player achievementsget_user_credits(player): Get player credit balance
Development Setup
Prerequisites
- Rust 1.86.0+
- cargo-near
Building
# Build main contract
cargo near build
# Build game contract
cd game_contract
cargo near build
Testing
# Test main contract
cargo test
# Test game contract
cd game_contract
cargo test
Deployment
# Deploy main contract
cargo near deploy build-reproducible-wasm <main-contract-account-id>
# Deploy game contract
cd game_contract
cargo near deploy build-reproducible-wasm <game-contract-account-id>
Contract Initialization
Main Contract
near call $MAIN_CONTRACT new '{
"initial_admin": "$ADMIN_ACCOUNT",
"kim_token_contract": "$KIM_TOKEN_CONTRACT"
}' --accountId $MAIN_CONTRACT
Game Contract
near call $GAME_CONTRACT new '{
"posts_contract": "$MAIN_CONTRACT",
"kim_ft_id": "$KIM_TOKEN_CONTRACT",
"guesses_per_game": 2
}' --accountId $GAME_CONTRACT
Security Features
- Admin Controls: Only designated admins can verify posts
- Pause Mechanism: Contract can be paused for maintenance
- Stake Lockup: Prevents immediate withdrawal of stakes
- Input Validation: Comprehensive validation on all user inputs
- Cross-Contract Security: Proper validation of cross-contract calls
Badge System
Players earn badges based on performance:
- Accuracy Badges: 60%+ (Decent), 70%+ (Good), 80%+ (Expert), 90%+ (Master)
- Games Played: 5+ (New), 20+ (Regular), 50+ (Experienced), 100+ (Veteran)
- Streak Badges: 3+ (Mini), 5+ (Good), 7+ (Hot), 10+ (Master)
Useful Links
- cargo-near - NEAR smart contract development toolkit for Rust
- near CLI - Interact with NEAR blockchain from command line
- NEAR Rust SDK Documentation
- NEAR Documentation
- NEAR StackOverflow
- NEAR Discord
- NEAR Telegram Developers Community Group
- NEAR DevHub: Telegram, Twitter