Unfollow inactive users
Unfollow Farcaster users with Neynar
This guide demonstrates how to unfollow Farcasters who hasn't been active in the past 3 months.
Check out this Getting started guide to learn how to set up your environment and get an API key.
First, initialize the client:
// npm i @neynar/nodejs-sdk
import { NeynarAPIClient } from "@neynar/nodejs-sdk";
// make sure to set your NEYNAR_API_KEY .env
// don't have an API key yet? get one at neynar.com
const client = new NeynarAPIClient(process.env.NEYNAR_API_KEY);
const signer = process.env.NEYNAR_SIGNER;
In the fetchFollowing endpoint, there's an activeStatus
field that can be used to filter out inactive Farcasters.
const fid = 3;
const users = await client.fetchUserFollowing(fid);
console.log(users);
Will result in this:
{
"result": {
"users": [
{
"fid": 3461,
"custodyAddress": "0x094ce1566a83b632e59d50e2aa9618d0f4dcd432",
"username": "jonahg",
"displayName": "Jonah Grant",
"pfp": {
"url": "https://i.imgur.com/x51eW6a.jpg"
},
"profile": {
"bio": {
"text": "Software engineer in New York City",
"mentionedProfiles": []
}
},
"followerCount": 15,
"followingCount": 0,
"verifications": [],
"activeStatus": "inactive",
"timestamp": "2023-12-09T05:01:59.000Z"
},
{
"fid": 18198,
"custodyAddress": "0x718aea83c0ee2165377335a0e8ed48f1c5a34d63",
"username": "alive.eth",
"displayName": "Ali Yahya",
"pfp": {
"url": "https://i.imgur.com/1PASQSb.jpg"
},
"profile": {
"bio": {
"text": "GP @a16zcrypto. Previously Google Brain, GoogleX, Stanford Computer Science.",
"mentionedProfiles": []
}
},
"followerCount": 88,
"followingCount": 76,
"verifications": [
"0x990a73079425d2b0ec746e3cc989e903306bb6c7"
],
"activeStatus": "inactive",
"timestamp": "2023-12-08T16:58:51.000Z"
},
{
"fid": 9528,
"custodyAddress": "0x80ef8b51dbba18c50b3451acea9deebc7dfcd131",
"username": "skominers",
"displayName": "Scott Kominers ",
"pfp": {
"url": "https://i.imgur.com/lxEkagM.jpg"
},
"profile": {
"bio": {
"text": "@a16zcrypto • Harvard/HBS • 🧩 • QED",
"mentionedProfiles": []
}
},
"followerCount": 289,
"followingCount": 190,
"verifications": [
"0x34202f199ef058302dcced326a0105fe2db53e12"
],
"activeStatus": "active",
"timestamp": "2023-12-08T16:56:30.000Z"
}
],
"next": {
"cursor": "eyJ0aW1lc3RhbXAiOiIyMDIzLTEyLTA4IDE2OjU2OjMwLjAwMDAwMDAiLCJmaWQiOjk1Mjh9"
}
}
}
To get fids of inactive Farcasters, we can use the activeStatus
field to filter out active Farcasters.
const inactiveFids = users.result.users
.filter((user) => user.activeStatus === "inactive")
.map((user) => user.fid);
console.log(inactiveFids); // [ 3461, 18198 ]
And this inactiveFids
value can be passed to client.unfollowUser to unfollow inactive Farcasters.
await client.unfollowUser(signer, inactiveFids);
Which will result in this:
{
"success": true,
"details": [
{
"success": true,
"target_fid": 3461
},
{
"success": true,
"target_fid": 18198
},
]
}
That's it! You can now unfollow inactive Farcasters easily with the Neynar SDK.
Ready to start building?
Get your subscription at neynar.com and reach out to us on Telegram with any questions!
Updated 2 months ago