> ## 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.

# User Balances Directly with FID

> This guide provides a step-by-step approach to fetching token balances for a user using their Farcaster FID via the Neynar API.

<Info>
  ### Related API: [Token balance](/reference/fetch-user-balance)
</Info>

## Fetching User Balances Using Farcaster FID with Neynar API

This API abstracts the complexity of finding Ethereum addresses and querying multiple providers, allowing developers to retrieve balances with a single API call.

### Overview

* **API Endpoint**: `/farcaster/user/balance`

* **Method**: `GET`

* **Parameters**:

  * `fid` (required): The Farcaster FID of the user.
  * `networks` (required): A comma-separated list of networks to fetch balances for. Currently, only "base" is supported.

### Prerequisites

* **API Key**: Ensure you have a Neynar API key. You can obtain one by signing up at [neynar.com](https://neynar.com).
* **Node.js SDK**: Install the Neynar Node.js SDK.

<CodeGroup>
  ```bash Bash theme={"system"}
  npm install @neynar/nodejs-sdk
  ```
</CodeGroup>

### Fetching User Balances

<Steps>
  <Step title="Initialize the Neynar Client">
    First, set up the Neynar client using your API key.

    <CodeGroup>
      ```javascript javascript theme={"system"}
      import { NeynarAPIClient, Configuration } from "@neynar/nodejs-sdk";

      const config = new Configuration({
        apiKey: process.env.NEYNAR_API_KEY,
      });

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

  <Step title="Fetch User Balances">
    Use the `fetchUserBalance` method to retrieve the token balances for a user by their FID.

    <CodeGroup>
      ```javascript javascript theme={"system"}
      async function fetchUserBalances(fid) {
        try {
          const response = await client.fetchUserBalance({
            fid: fid,
            networks: ['base'], // Currently, only 'base' is supported
          });

          console.log("User Balances:", response.user_balance);
        } catch (error) {
          console.error("Error fetching user balances:", error);
        }
      }

      // Example usage
      fetchUserBalances(3); // Replace '3' with the actual FID
      ```
    </CodeGroup>
  </Step>
</Steps>

#### Response Structure

The response will include the user's balance information structured as follows:

<CodeGroup>
  ```json json theme={"system"}
  {
    "user_balance": {
      "object": "user_balance",
      "user": {
        "fid": 3,
        "username": "example_user",
        // Additional user details
      },
      "address_balances": [
        {
          "object": "address_balance",
          "verified_address": {
            "address": "0x1234567890abcdef",
            "network": "base"
          },
          "token_balances": [
            {
              "object": "token_balance",
              "token": {
                "object": "token",
                "name": "Ethereum",
                "symbol": "ETH",
                "decimals": 18
              },
              "balance": {
                "in_token": "1.2345",
                "in_usdc": "1234.56"
              }
            }
            // Additional tokens
          ]
        }
        // Additional addresses
      ]
    }
  }
  ```
</CodeGroup>

### Error Handling

Ensure to handle potential errors, such as invalid FID or network issues, by wrapping your API calls in try-catch blocks.

### Conclusion

By following this guide, you can efficiently fetch token balances for a user using their Farcaster FID with the Neynar API. This streamlined process eliminates the need for multiple API calls and simplifies the integration into your application.

<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>
