> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neynar.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Find Mutual Follows and Followers

> Learn how to find mutual follows and followers between Farcaster users using Neynar API. Build social discovery features like 'Followed by X users you follow' similar to Twitter, with comprehensive examples and SDK integration for enhanced user connections.

<Info>
  ### This guide refers to [this API](/reference/fetch-relevant-followers)
</Info>

## How to Find Mutual Follows and Followers

On X (Twitter) profile page, there is a "Followed by A, B, C, and 10 others you follow". This guide demonstrates how to use the Neynar SDK to make the same thing but for Farcaster.

Check out this [Getting started guide](/docs/getting-started-with-neynar) to learn how to set up your environment and get an API key.

First, initialize the client:

<CodeGroup>
  ```javascript Javascript theme={"system"}
  // npm i @neynar/nodejs-sdk
  import { NeynarAPIClient, Configuration } 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 config = new Configuration({
    apiKey:process.env.NEYNAR_API_KEY,
  });

  const client = new NeynarAPIClient(config);
  ```
</CodeGroup>

Say we want to get people @rish follows that also follows @manan. This is useful if we want to mutual connections between two users. We'll fetch @rish's followings first.

<CodeGroup>
  ```javascript Javascript theme={"system"}
  const fetchAllFollowing = async (fid: number) => {
    let cursor: string | null = "";
    let users: unknown[] = [];
    do {
      const result = await client.fetchUserFollowing({fid,
        limit: 150,
        cursor,
      });
      users = users.concat(result.result.users);
      cursor = result.result.next.cursor;
      console.log(cursor);
    } while (cursor !== "" && cursor !== null);

    return users;
  };

  const rishFID = 194;
  const rishFollowings = await fetchAllFollowing(rishFID);
  ```
</CodeGroup>

Then we'll fetch @manan's followers.

<CodeGroup>
  ```javascript Javascript theme={"system"}
  const fetchAllFollowers = async (fid: number) => {
    let cursor: string | null = "";
    let users: unknown[] = [];
  const limit=150
    do {
      const result = await client.fetchUserFollowers({fid,
        limit,
        cursor,
      });
      users = users.concat(result.result.users);
      cursor = result.result.next.cursor;
      console.log(cursor);
    } while (cursor !== "" && cursor !== null);

    return users;
  };

  const mananFID = 191;
  const mananFollowers = await fetchAllFollowers(mananFID);
  ```
</CodeGroup>

Think of these two arrays as sets. We want to find the intersection of these two sets. We can use the `fid` property to find the intersection.

<CodeGroup>
  ```javascript Javascript theme={"system"}
  const mutualFollowings = rishFollowings.filter((following) =>
    mananFollowers.some((follower) => follower.fid === following.fid)
  );

  console.log(mutualFollowings);
  ```
</CodeGroup>

Example output:

```json theme={"system"}
[
  {
    fid: 6227,
    custodyAddress: "0x35b92ea9c3819766ec1fff8ddecec69028b0ac42",
    username: "ekinci.eth",
    displayName: "Emre Ekinci ~ q/dau",
    pfp: {
      url: "https://i.imgur.com/smbrNPw.jpg"
    },
    profile: {
      bio: [Object ...]
    },
    followerCount: 670,
    followingCount: 660,
    verifications: [ "0x5f57c686bdbc03242c8fa723b80f0a6cdea79546"
    ],
    activeStatus: "active",
    timestamp: "2023-11-14T04:13:11.000Z"
  }, {
    fid: 280,
    custodyAddress: "0xd05d60b5762728466b43dd94ba882d050b60af67",
    username: "vrypan.eth",
    displayName: "vrypan.eth",
    pfp: {
      url: "https://i.imgur.com/jmXEW3I.png"
    },
    profile: {
      bio: [Object ...]
    },
    followerCount: 1296,
    followingCount: 493,
    verifications: [ "0x8b0573d1c80362db589eda39c2e30f5190d7eb51",
      "0x93c620d2af377c6c37e3e3c1d3e065eb04b08ae2"
    ],
    activeStatus: "active",
    timestamp: "2023-11-14T01:37:40.000Z"
  }
  // ...
]
```

<Info>
  you'd probably want to cache the results of `fetchAllFollowing` and `fetchAllFollowers` so you don't have to make the same API calls again.
</Info>

That's it! You can use this to make a "Followed by A, B, C, and 10 others you follow" info in your Farcaster app.

<Info>
  ### Ready to start building?

  Get your subscription at [neynar.com](https://neynar.com) and reach out to us on [Slack](https://neynar.com/slack) with any questions!
</Info>
