Embed casts from Farcaster in your React app.
npm install react-farcaster-embedDisplay an embedded cast from Farcaster in your React app. Works with Next.js SSR.
Regular casts
Quoted casts
With images
With video
With link previews
- [x] Supports server components and client components
- [x] Shows the cast's author, their avatar and username, date when the cast was posted
- [x] Renders the cast's content with links
- [x] Shows the channel name and avatar
- [x] Shows counts for replies, likes, recasts + quotes, watches
- [x] Adds a link to the cast on Farcaster
- [x] Renders images inline
- [x] Renders videos inline
- [x] Renders rich embeds for links
- [x] Renders quoted casts with images and videos
- [ ] Renders a frame preview with buttons
``shell`
npm i react-farcaster-embedor
yarn add react-farcaster-embedor
pnpm add react-farcaster-embed
Add these imports inside your server component:
`jsx
import { FarcasterEmbed } from "react-farcaster-embed";
import "react-farcaster-embed/dist/styles.css"; // include default styles or write your own
// use farcaster url
// or username and hash of the cast
`
Add the CSS import inside _app.tsx if you are using Next.js Pages Router:
`tsx
import "@/styles/globals.css";
import "react-farcaster-embed/dist/styles.css";
import type { AppProps } from "next/app";
export default function App({ Component, pageProps }: AppProps) {
return
}
`
And then use the component in your client component using a special import:
`jsx
import { FarcasterEmbed } from "react-farcaster-embed/dist/client";
// use farcaster url
// or username and hash of the cast
`
The embed will inherit your body color by default when you import the default stylesheet.
You can change the color of the component by changing its parent's color or adding custom CSS:
`css`
.farcaster-embed-container {
color: purple;
}
In case you need to self host the Farcaster Client API proxy, you can fork this repo and set the customEndpoint option in the FarcasterEmbed component.
Easiest way to do this is to make a wrapper component with that option applied. Example:
`jsx
import { FarcasterEmbed as FCEmbed } from "react-farcaster-embed";
export const FarcasterEmbed = (props) => (
options={{
customEndpoint: "https://your-endpoint.xyz/api/casts",
}}
/>
);
`
Casts will be fetched from your custom proxy instead of the default one using this URL structure. Make sure your proxy supports it.
`jsx${options?.customEndpoint}/${username}/${hash}
await fetch();`
Farcaster's API will not return anything when the cast has been deleted, so this is useful if you want to display deleted casts from archival data using your own indexer. Use the castData prop to pass in the cast's JSON into the component to render.
`jsx
const data = {
/ cast data coming from your own indexer or Neynar /
};
`
You can use the silentError option to prevent errors from being thrown when the cast is deleted or unable to be fetched.
Easiest way to do this is to make a wrapper component with that option applied. Example:
`jsx
import { FarcasterEmbed as FCEmbed } from "react-farcaster-embed";
export const FarcasterEmbed = (props) => (
options={{
silentError: true,
}}
/>
);
`
You can hide the Farcaster logo link by setting the hideFarcasterLogo option to true.
`jsx`
Follow me on Farcaster or Twitter.
Send me a tip in ETH or $DEGEN to
- pugson.eth0x96a77560146501eAEB5e6D5B7d8DD1eD23DEfa23`
-
You might also like ENS Data for getting ENS records and avatars or ABI Data for grabbing smart contract ABIs remotely.