5.4 KiB
5.4 KiB
โ Use Existing Farcaster Accounts
๐ฏ No Registration Needed!
PollCelo users already have Farcaster accounts because they're using Warpcast. We just need to access their existing FID.
๐ก How It Works
Frame SDK Provides Everything
import sdk from '@farcaster/frame-sdk'
// Get user's existing Farcaster account
const context = await sdk.context
const fid = context.user.fid // Their FID
const username = context.user.username // Their username
const pfp = context.user.pfpUrl // Their profile pic
No registration needed! No $5 fee! Users already authenticated!
๐ Updated Implementation
Remove Registration Flow
// โ OLD: Force users to register
router.push('/register')
// โ
NEW: Use their existing account
const context = await sdk.context
const fid = context.user.fid
// Ready to vote!
Simple Auth Check
// app/page.tsx or any protected page
useEffect(() => {
const checkAuth = async () => {
const context = await sdk.context
if (!context?.user?.fid) {
// User not in Warpcast - show message
setError('Please open in Warpcast app')
return
}
// User authenticated, ready to use
setFid(context.user.fid)
}
checkAuth()
}, [])
๐ What Users Have
When users open PollCelo in Warpcast, they already have:
- โ Farcaster ID (FID)
- โ Username (@username)
- โ Profile picture
- โ Account keys (managed by Warpcast)
- โ Authentication
Cost to user: $0 Setup time: 0 seconds
๐ง Updated File Structure
Remove These (Not Needed)
โ lib/farcaster/register.ts
โ lib/farcaster/register-app.ts
โ lib/farcaster/add-key.ts
โ app/api/farcaster/register/route.ts
โ app/api/farcaster/add-key/route.ts
โ app/register/page.tsx
โ scripts/register-app.ts
Keep These (Useful)
โ
lib/farcaster/username.ts # Lookup users
โ
app/api/farcaster/username/route.ts # Username API
โ
components/UsernameSearch.tsx # Search component
๐ฐ Cost Comparison
| Method | User Cost | App Cost | Setup Time |
|---|---|---|---|
| โ New Registration | $5 | $0 | 30 seconds |
| โ Existing Account | $0 | $0 | 0 seconds |
๐ฏ User Flow
Old (Bad)
User opens app
โ
"Create Farcaster account"
โ
Pay $5
โ
Wait 30 seconds
โ
Finally can vote
New (Good)
User opens app in Warpcast
โ
Already authenticated
โ
Vote immediately! โ
๐ Authentication
Get User Info
import sdk from '@farcaster/frame-sdk'
const context = await sdk.context
// User info
const fid = context.user.fid
const username = context.user.username
const displayName = context.user.displayName
const pfpUrl = context.user.pfpUrl
const bio = context.user.profile.bio
// Use in your app
await createVote(pollId, optionId, fid)
await createComment(pollId, content, fid)
Check If Authenticated
if (!context?.user?.fid) {
return (
<div className="text-center p-8">
<p className="text-white text-xl mb-4">
Please open PollCelo in Warpcast
</p>
<a
href="https://warpcast.com"
className="text-celo-green hover:underline"
>
Download Warpcast โ
</a>
</div>
)
}
๐จ Updated UI
Header Component
// components/Header.tsx
import sdk from '@farcaster/frame-sdk'
export default function Header() {
const [user, setUser] = useState<any>(null)
useEffect(() => {
sdk.context.then(ctx => setUser(ctx.user))
}, [])
return (
<header>
{user && (
<div className="flex items-center gap-2">
<img src={user.pfpUrl} className="w-8 h-8 rounded-full" />
<span>@{user.username}</span>
<span className="text-gray-400">FID: {user.fid}</span>
</div>
)}
</header>
)
}
โ Benefits
For Users
- โ No registration
- โ No $5 fee
- โ Instant access
- โ Use existing identity
- โ No new keys to manage
For You
- โ No registration code to maintain
- โ No app FID needed
- โ No OP Mainnet RPC needed
- โ No ETH for gas
- โ Simpler codebase
๐งน Cleanup Steps
1. Remove Registration Files
rm -rf lib/farcaster/register*.ts
rm -rf lib/farcaster/add-key.ts
rm -rf app/api/farcaster/register
rm -rf app/api/farcaster/add-key
rm -rf app/register
rm -rf scripts/register-app.ts
2. Remove Environment Variables
# Remove from .env.local
# โ OP_MAINNET_RPC_URL
# โ APP_PRIVATE_KEY
3. Update Dependencies
# Can remove if not using for other features
npm uninstall @farcaster/hub-nodejs @noble/ed25519
๐ Updated Documentation
Remove These Docs
โ FARCASTER_REGISTRATION.md
โ FARCASTER_BUNDLER.md
โ FARCASTER_KEYS.md
โ FARCASTER_SETUP.md
โ FARCASTER_INTEGRATION.md
โ FARCASTER_FINAL.md
Keep This
โ
FARCASTER_EXISTING_ACCOUNTS.md (this file)
โ
FARCASTER_USERNAME.md (username lookup)
๐ Summary
Old Approach:
- โ Users pay $5
- โ 30 second wait
- โ Complex implementation
- โ Maintenance burden
New Approach:
- โ Users pay $0
- โ Instant access
- โ Simple implementation
- โ Use Frame SDK
PollCelo users already have Farcaster accounts - just use them! ๐