Introduction
Farcaster is a protocol for building decentralized social apps. Neynar makes it easy to build on Farcaster. This tutorial covers- fundamentals of Farcaster protocol
- getting your Neynar API key
- understanding core concepts like FIDs and Casts
- tutorial steps to start developing social applications
Basic understanding of Farcaster
Farcaster is a decentralized social protocol. Here are a few of the primary Farcaster primitives that will be helpful to keep in mind as you dive in:User
Every user on Farcaster is represented by a permanent FID, the user’s numerical identifier. All user profile data for this FID, e.g., username, display name, bio, etc., are stored on the Farcaster protocol and mapped to this FID.
Casts
Users can broadcast information to the protocol in units of information called “casts”. It’s somewhat similar to a tweet on Twitter/X. Each cast has a unique “hash”.
User Relationships
Users can follow each other to see casts from them. This creates a social graph for each user on Farcaster.
Get Neynar API key
Don’t have an API key yet? Create an account to get started. Don’t hesitate to reach out to us on our channel or Slack with any questions!If building a mini app, you can go straight to Set up mini app in < 60 s
Set up Neynar SDK
Neynarnodejs
SDK is an easy way to use the APIs. This section only needs to be done once when setting up the SDK for the first time.
To install the Neynar TypeScript SDK:
index.ts
:
1
check the
type
field in package.json. Since we’re using ES6 modules, you may need to set it to “module”.2
If you hit errors, try adding a
tsconfig.json
file in the directory to help with typescript compilation- node_modules
- index.ts
- package-lock.json
- package.json
- tsconfig.json (optional)
- yarn.lock
Fetch Farcaster data using Neynar SDK
Fetching feed
To fetch the feed for a user, you need to know who the user is following and then fetch casts from those users. Neynar abstracts away all this complexity. Put in thefid
of the user in the fetchFeed
function and get a feed in response.
In this example, we will fetch the feed for Dan Romero . This is the feed Dan would see if he were to log into a client that showed a feed from people he followed in a reverse chronological order.