Getting started
Start building on Farcaster with Neynar
Farcaster is a protocol for building decentralized social apps. Neynar makes it easy to build on Farcaster.
API key
Don't have an API key yet? Register now at neynar.com.
- Click "Subscribe now."
- You will be redirected to a Stripe checkout page.
- Upon successful payment, we'll send you an email. Once the email arrives, you'll be able to sign in to the Developer Portal
Don't hesitate to reach out to us on our channel or Telegram with any questions!
SDK
To install the Neynar TypeScript SDK:
npm install @neynar/nodejs-sdk
yarn add @neynar/nodejs-sdk
pnpm install @neynar/nodejs-sdk
bun add @neynar/nodejs-sdk
To get started, initialize the client:
import { NeynarAPIClient } from "@neynar/nodejs-sdk";
// make sure to set your NEYNAR_API_KEY .env
const client = new NeynarAPIClient(process.env.NEYNAR_API_KEY);
If you encounter module errors, check the 'type' field in package.json. Since we're using ES6 modules, you may need to set it to "module".
{
"name": "your-project",
"type": "module" // <-- set to module if needed
}
Some examples of what you can do with the Neynar SDK:
// fetch a single cast
const hash = "0x8ffed4e8fa53c6e22b85f678c9a53067826e846a";
const cast = await client.lookUpCastByHash(hash);
console.log(cast); // logs information about the cast
// fetch info about a Farcaster user
const fid = 3;
const user = await client.lookupUserByFid(fid);
console.log(user); // logs information about the user
API endpoints
Neynar also provides a REST API to read and write data on Farcaster. Read the docs.
Here's an example of fetching cast and user data but with the REST API:
const base = "https://api.neynar.com/";
const apiKey = process.env.NEYNAR_API_KEY;
const hash = "0x8ffed4e8fa53c6e22b85f678c9a53067826e846a";
const cast_url = `${base}v2/farcaster/cast?identifier=${hash}&type=hash`;
const cast_response = await fetch(cast_url, {
headers: {
'Content-Type': 'application/json',
'Content-Encoding': 'gzip, deflate, br',
'api_key': apiKey,
},
});
const cast = await cast_response.json();
console.log(cast); // logs information about the cast
const fid = 3;
const user_url = `${base}v1/farcaster/user?fid=${fid}`;
const user_response = await fetch(user_url, {
headers: {
'Content-Type': 'application/json',
'Content-Encoding': 'gzip, deflate, br',
'api_key': apiKey,
},
});
const user = await user_response.json();
console.log(user); // logs information about the user
Any v1 APIs that have been deprecated are marked so. All other v1 endpoints are actively maintained.
Updated 4 days ago