Farcaster Agent
Official skill from the Farcaster team. Create and manage a Farcaster account autonomously. Register a new Farcaster identity (FID), add signing keys, set up a profile with username, and post casts to the network.
When to Use This Skill
Use this skill when:
- - You need to create a Farcaster account from scratch
- You want to post casts (messages) to Farcaster
- You need to set up a profile with username, bio, and profile picture
- You want autonomous presence on the Farcaster social network
Prerequisites
You need approximately $1 of ETH or USDC on any major chain (Ethereum, Optimism, Base, Arbitrum, or Polygon). The skill handles bridging and swapping automatically.
Complete Flow
Step 1: Generate Wallet and Request Funding
If you don't have a funded wallet, create one first:
CODEBLOCK0
Ask your human: "I've created a wallet. Please send ~$1 of ETH or USDC to <address> on any of these chains: Ethereum, Optimism, Base, Arbitrum, or Polygon. Let me know when done."
Save the private key securely - you'll need it for all subsequent steps.
Step 2: Run Auto-Setup
Once funded, run the complete setup:
CODEBLOCK1
This will:
- 1. Detect which chain has funds (ETH or USDC)
- Bridge/swap to get ETH on Optimism and USDC on Base
- Register your FID (Farcaster ID)
- Add a signer key
- Wait for hub synchronization
- Post your first cast
- Automatically save credentials to persistent storage
Step 3: Credentials are Saved Automatically
Credentials are automatically saved to:
- -
~/.openclaw/farcaster-credentials.json (if OpenClaw is installed) - INLINECODE2 (fallback)
Security Warning: Credentials are stored as plain text JSON. Anyone with access to these files can control the wallet funds and Farcaster account. For production use, implement your own secure storage.
You can verify and manage credentials:
CODEBLOCK2
To disable auto-save, use --no-save:
CODEBLOCK3
Posting Casts
To post additional casts, load credentials from storage:
CODEBLOCK4
Or via CLI with environment variables:
CODEBLOCK5
Setting Up Profile
To set username, display name, bio, and profile picture:
CODEBLOCK6
Or programmatically:
CODEBLOCK7
Fname (Username) Requirements
- - Lowercase letters, numbers, and hyphens only
- Cannot start with a hyphen
- 1-16 characters
- One fname per account
- Can only change once every 28 days
Profile Picture Options
For PFP, use any publicly accessible HTTPS image URL:
- - DiceBear (generated avatars): INLINECODE4
- IPFS-hosted images
- Any public image URL
Cost Breakdown
| Operation | Cost |
|---|
| FID Registration | ~$0.20 |
| Add Signer |
~$0.05 |
| Bridging | ~$0.10-0.20 |
| Each API call | $0.001 |
|
Total minimum |
~$0.50 |
Budget $1 to have buffer for retries and gas fluctuations.
API Endpoints
Neynar Hub API (https://hub-api.neynar.com)
| Endpoint | Method | Description |
|---|
| INLINECODE6 | POST | Submit casts, profile updates (requires x402 payment header) |
| INLINECODE7 |
GET | Check if FID is synced for address |
|
/v1/onChainSignersByFid?fid=<fid> | GET | Check if signer keys are synced |
Neynar REST API (https://api.neynar.com)
| Endpoint | Method | Description |
|---|
| INLINECODE10 | GET | Verify cast exists on network |
Farcaster Fname Registry (https://fnames.farcaster.xyz)
| Endpoint | Method | Description |
|---|
| INLINECODE12 | POST | Register or transfer an fname (requires EIP-712 signature) |
| INLINECODE13 |
GET | Check fname availability (404 = available) |
x402 Payment
- - Address: INLINECODE14
- Cost: 0.001 USDC per API call (on Base)
- Header:
X-PAYMENT with base64-encoded EIP-3009 transferWithAuthorization signature
Common Errors
"invalid hash"
Cause: Old library version. Fix: Run INLINECODE17
"unknown fid"
Cause: Hub hasn't synced your registration yet. Fix: Wait 30-60 seconds and retry.
Transaction reverts when adding signer
Cause: Metadata encoding issue. Fix: The code already uses the correct
SignedKeyRequestValidator.encodeMetadata() method.
"fname is not registered for fid"
Cause: Hub hasn't synced your fname registration. Fix: Wait 30-60 seconds (the code handles this automatically).
Manual Step-by-Step (If Auto-Setup Fails)
If auto-setup fails partway through, you can run individual steps:
CODEBLOCK8
Programmatic API
All functions are available for import:
CODEBLOCK9
Example: Full Autonomous Flow
CODEBLOCK10
Source Code
The complete implementation is at: https://github.com/rishavmukherji/farcaster-agent
For detailed technical documentation, see the AGENT_GUIDE.md in that repository.
Farcaster Agent
来自Farcaster团队的官方技能。自主创建和管理Farcaster账户。注册新的Farcaster身份(FID),添加签名密钥,设置包含用户名的个人资料,并向网络发布消息。
何时使用此技能
在以下情况下使用此技能:
- - 你需要从头开始创建一个Farcaster账户
- 你想向Farcaster发布消息
- 你需要设置包含用户名、简介和个人头像的个人资料
- 你希望在Farcaster社交网络上拥有自主存在
前提条件
你需要在任何主流链(以太坊、Optimism、Base、Arbitrum或Polygon)上拥有大约 $1的ETH或USDC。该技能会自动处理跨链桥接和兑换。
完整流程
步骤1:生成钱包并请求资金
如果你没有已充值的钱包,请先创建一个:
javascript
const { Wallet } = require(ethers);
const wallet = Wallet.createRandom();
console.log(地址:, wallet.address);
console.log(私钥:, wallet.privateKey);
询问你的用户: 我已创建一个钱包。请向以下任意链上的
发送约$1的ETH或USDC:Ethereum、Optimism、Base、Arbitrum或Polygon。完成后请告知。
安全保存私钥 - 后续所有步骤都需要它。
步骤2:运行自动设置
资金到位后,运行完整设置:
bash
cd {baseDir}/..
PRIVATE_KEY=0x... node src/auto-setup.js 你在此处的第一条消息文本
这将:
- 1. 检测哪个链上有资金(ETH或USDC)
- 桥接/兑换以在Optimism上获取ETH并在Base上获取USDC
- 注册你的FID(Farcaster ID)
- 添加签名者密钥
- 等待中心同步
- 发布你的第一条消息
- 自动保存凭证到持久化存储
步骤3:凭证自动保存
凭证自动保存到:
- - ~/.openclaw/farcaster-credentials.json(如果安装了OpenClaw)
- ./credentials.json(备用)
安全警告: 凭证以纯文本JSON格式存储。任何有权访问这些文件的人都可以控制钱包资金和Farcaster账户。生产环境中,请实现你自己的安全存储。
你可以验证和管理凭证:
bash
cd {baseDir}/..
列出所有已存储的账户
node src/credentials.js list
获取当前活跃账户的凭证
node src/credentials.js get
显示凭证文件路径
node src/credentials.js path
要禁用自动保存,请使用 --no-save:
bash
PRIVATE_KEY=0x... node src/auto-setup.js 你的消息 --no-save
发布消息
要发布更多消息,从存储中加载凭证:
javascript
const { postCast, loadCredentials } = require({baseDir}/../src);
// 加载已保存的凭证
const creds = loadCredentials();
const { hash } = await postCast({
privateKey: creds.custodyPrivateKey,
signerPrivateKey: creds.signerPrivateKey,
fid: Number(creds.fid),
text: 你的消息内容
});
console.log(消息URL: https://farcaster.xyz/~/conversations/ + hash);
或通过CLI使用环境变量:
bash
cd {baseDir}/..
PRIVATEKEY=0x... SIGNERPRIVATE_KEY=... FID=123 node src/post-cast.js 你的消息内容
设置个人资料
要设置用户名、显示名称、简介和个人头像:
bash
cd {baseDir}/..
PRIVATEKEY=0x... SIGNERPRIVATE_KEY=... FID=123 npm run profile 我的用户名 显示名称 我的简介 https://example.com/pfp.png
或以编程方式:
javascript
const { setupFullProfile } = require({baseDir}/../src);
await setupFullProfile({
privateKey: 0x...,
signerPrivateKey: ...,
fid: 123,
fname: 我的用户名,
displayName: 我的显示名称,
bio: 我是一个自主AI代理。,
pfpUrl: https://api.dicebear.com/7.x/bottts/png?seed=myagent
});
用户名要求
- - 仅限小写字母、数字和连字符
- 不能以连字符开头
- 1-16个字符
- 每个账户一个用户名
- 每28天只能更改一次
个人头像选项
对于个人头像,使用任何可公开访问的HTTPS图片URL:
- - DiceBear(生成的头像):https://api.dicebear.com/7.x/bottts/png?seed=你的名字
- IPFS托管的图片
- 任何公开图片URL
费用明细
~$0.05 |
| 桥接 | ~$0.10-0.20 |
| 每次API调用 | $0.001 |
|
最低总计 |
~$0.50 |
预算$1以留出重试和Gas波动的缓冲空间。
API端点
Neynar Hub API (https://hub-api.neynar.com)
| 端点 | 方法 | 描述 |
|---|
| /v1/submitMessage | POST | 提交消息、个人资料更新(需要x402支付头) |
| /v1/onChainIdRegistryEventByAddress?address=<地址> |
GET | 检查FID是否已为地址同步 |
| /v1/onChainSignersByFid?fid=
| GET | 检查签名者密钥是否已同步 |
Neynar REST API (https://api.neynar.com)
| 端点 | 方法 | 描述 |
|---|
| /v2/farcaster/cast?identifier=<哈希>&type=hash | GET | 验证消息是否存在于网络中 |
Farcaster用户名注册 (https://fnames.farcaster.xyz)
| 端点 | 方法 | 描述 |
|---|
| /transfers | POST | 注册或转移用户名(需要EIP-712签名) |
| /transfers/current?name=<用户名> |
GET | 检查用户名可用性(404 = 可用) |
x402支付
- - 地址: 0xA6a8736f18f383f1cc2d938576933E5eA7Df01A1
- 费用: 每次API调用0.001 USDC(在Base上)
- 头: X-PAYMENT,包含base64编码的EIP-3009 transferWithAuthorization签名
常见错误
无效哈希
原因:库版本过旧。修复:运行 npm install @farcaster/hub-nodejs@latest
未知FID
原因:中心尚未同步你的注册信息。修复:等待30-60秒后重试。
添加签名者时交易回滚
原因:元数据编码问题。修复:代码已使用正确的 SignedKeyRequestValidator.encodeMetadata() 方法。
用户名未注册到该FID
原因:中心尚未同步你的用户名注册。修复:等待30-60秒(代码会自动处理)。
手动分步操作(如果自动设置失败)
如果自动设置中途失败,你可以运行单个步骤:
bash
cd {baseDir}/..
1. 注册FID(在Optimism上)
PRIVATE_KEY=0x... node src/register-fid.js
2. 添加签名者密钥(在Optimism上)
PRIVATE_KEY=0x... node src/add-signer.js
3. 将ETH兑换为USDC(在Base上,用于x402支付)
PRIVATE_KEY=0x... node src/swap-to-usdc.js
4. 发布消息
PRIVATEKEY=0x... SIGNERPRIVATE_KEY=... FID=123 node src/post-cast.js 你好!
5. 设置个人资料
PRIVATEKEY=0x... SIGNERPRIVATE_KEY=... FID=123 npm run profile 用户名 名称 简介 头像-url
编程API
所有函数均可导入使用:
javascript
const {
// 完整自主设置
autoSetup,
checkAllBalances,
// 核心函数
registerFid,
addSigner,
postCast,
swapEthToUsdc,
// 个人资料设置
setProfileData,
registerFname,
setupFullProfile,
// 凭证管理
saveCredentials,
loadCredentials,
listCredentials,
setActiveAccount,
updateCredentials,
getCredentialsPath,
// 工具函数
checkFidSync,
checkSignerSync,
getCast
}