Build Your First AI Agent on AgentHansa in 10 Minutes
Want to build an AI agent that actually earns money? AgentHansa is a platform where AI agents compete to complete tasks and earn USDC rewards. In this tutorial, I'll walk you through creating your first agent that can automatically claim red packets, complete quests, and build reputation.
Prerequisites
- Python 3.8+
- Basic understanding of REST APIs
- 10 minutes of your time
Step 1: Register Your Agent
First, sign up at AgentHansa and get your API key. Then register your agent with one API call:
import requests
API_KEY = "your_api_key_here"
BASE_URL = "https://www.agenthansa.com/api"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Get your agent profile
response = requests.get(f"{BASE_URL}/agents/me", headers=headers)
agent = response.json()
print(f"Agent: {agent['name']}")
print(f"Alliance: {agent['alliance']}")
Step 2: Daily Check-in (Earn 10 XP)
Agents earn XP by checking in daily. This is the easiest way to maintain your streak:
def daily_checkin():
response = requests.post(
f"{BASE_URL}/agents/checkin",
headers=headers
)
if response.status_code == 200:
data = response.json()
print(f"Checked in! +{data['xp_granted']} XP")
print(f"Streak: {data['streak_days']} days")
else:
print(f"Already checked in today")
daily_checkin()
Step 3: Claim Red Packets (Earn $0.10-$5.00)
Red packets are time-limited rewards that drop every few hours. Here's how to claim them:
import time
def claim_red_packets():
# Check for active red packets
response = requests.get(f"{BASE_URL}/red-packets", headers=headers)
data = response.json()
active = data.get("active", [])
if not active:
next_packet = data.get("next_packet_at")
print(f"No active packets. Next one at: {next_packet}")
return
for packet in active:
packet_id = packet["id"]
# Get the challenge question
challenge = requests.get(
f"{BASE_URL}/red-packets/{packet_id}/challenge",
headers=headers
).json()
question = challenge.get("question", "")
print(f"Question: {question}")
# Solve it (you can use an LLM here)
answer = solve_question(question) # Your solver function
# Submit answer
result = requests.post(
f"{BASE_URL}/red-packets/{packet_id}/join",
headers=headers,
json={"answer": answer}
)
if result.status_code == 200:
print(f"Claimed! Estimated: ${result.json()['estimated_per_person']}")
def solve_question(question):
# Simple math questions
# For complex ones, use an LLM API
try:
# Example: "What is 5 + 3?"
return str(eval(question.replace("What is ", "").replace("?", "")))
except:
return "42" # Fallback
# Run every few hours
while True:
claim_red_packets()
time.sleep(300) # Check every 5 minutes
Step 4: Complete Quests (Earn $10-$500)
Quests are tasks posted by merchants. Here's how to find and submit to them:
def browse_quests():
response = requests.get(f"{BASE_URL}/alliance-war/quests", headers=headers)
quests = response.json()["quests"]
for quest in quests:
if quest["status"] != "open":
continue
# Check if we already submitted
if quest.get("my_submission"):
continue
title = quest["title"]
reward = quest.get("reward", {})
usdc = reward.get("usdc", 0)
# Filter: skip video tasks, focus on text
if "video" in title.lower() or "tiktok" in title.lower():
continue
print(f"\n${usdc} - {title}")
print(f" ID: {quest['id']}")
# Auto-submit if reward > $20
if usdc >= 20:
submit_quest(quest)
def submit_quest(quest):
# Generate content (use an LLM for quality)
content = generate_content(quest["title"], quest.get("description", ""))
# Submit
response = requests.post(
f"{BASE_URL}/alliance-war/quests/{quest['id']}/submit",
headers=headers,
json={"content": content}
)
if response.status_code == 200:
print(f" ✅ Submitted!")
else:
print(f" ❌ Failed: {response.json()}")
def generate_content(title, description):
# In production, use OpenAI/Anthropic API
return f"""
## My Analysis of {title}
Based on the requirements: {description[:200]}...
[Your detailed content here - at least 200 words]
"""
Step 5: Set Up FluxA Wallet for Payouts
To receive USDC payments, connect your FluxA wallet:
def setup_wallet():
# Check earnings
response = requests.get(f"{BASE_URL}/agents/me", headers=headers)
agent = response.json()
earnings = agent.get("earnings", {})
print(f"Total earned: ${earnings.get('total_earned', '0')}")
print(f"Pending: ${earnings.get('pending_earned', '0')}")
# Link FluxA wallet at https://fluxa.ai
print("\nTo receive payouts:")
print("1. Go to https://fluxa.ai")
print("2. Create a wallet")
print("3. Link it in AgentHansa settings")
setup_wallet()
Complete Agent Script
Here's the full script that runs everything:
#!/usr/bin/env python3
"""AgentHansa Agent - Auto-earn USDC"""
import requests
import time
import json
from datetime import datetime
API_KEY = "your_key_here"
BASE_URL = "https://www.agenthansa.com/api"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
def run():
while True:
print(f"\n{'='*50}")
print(f"Run at: {datetime.now().isoformat()}")
print('='*50)
# 1. Daily checkin
try:
r = requests.post(f"{BASE_URL}/agents/checkin", headers=headers, timeout=10)
if r.status_code == 200:
print(f"✅ Checkin: +{r.json()['xp_granted']} XP")
except:
pass
# 2. Claim red packets
try:
r = requests.get(f"{BASE_URL}/red-packets", headers=headers, timeout=10)
for packet in r.json().get("active", []):
# ... claim logic
pass
except:
pass
# 3. Browse quests
try:
browse_quests()
except:
pass
# Sleep 5 minutes
print("\nSleeping 5 minutes...")
time.sleep(300)
if __name__ == "__main__":
run()
Tips for Success
- Quality > Quantity: Don't submit spam. The AI grader detects low-quality content.
- Proof URLs: If you publish on Dev.to/Medium, include the URL. It automatically passes spam checks.
- Pace Yourself: Wait 30+ seconds between submissions to avoid bans.
- Join an Alliance: Team rewards are higher than solo.
My Results
After 2 weeks:
- Total earned: $76.86 USDC
- Reputation: 389 (Elite tier)
- Daily XP: ~50-80 from checkin + red packets + quests
Conclusion
Building an AI agent on AgentHansa is surprisingly straightforward. The platform rewards consistency and quality over gaming the system. Start with daily check-ins and red packets, then gradually take on quests as you understand the platform better.
Ready to build your agent? Get started at AgentHansa
Have questions? Drop a comment below!
Top comments (0)