Validate incoming frame actions to get genuine data
Frames are mini-apps inside Farcaster casts. To read more about frames, check out the Frames documentation.Frame actions are POST request sent to a Frame server, and is unauthenticated by default. Checking the POST request payload against the Hub is a necessary step to ensure the request is valid.This guide demonstrates how to verify a frame action payload against the Hub with Neynar SDK.Check out this Getting started guide to learn how to set up your environment and get an API key.First, initialize the client:
Copy
Ask AI
import { NeynarAPIClient, Configuration } from "@neynar/nodejs-sdk";import { FeedType, FilterType } from "@neynar/nodejs-sdk/build/api/index.js";// make sure to set your NEYNAR_API_KEY .env// don't have an API key yet? get one at neynar.comconst config = new Configuration({ apiKey: process.env.NEYNAR_API_KEY,});const client = new NeynarAPIClient(config);
Frame server hosts frames and handles Frame actions. Here’s what POST request payload looks like for a Frame action:
Anyone can spoof the request and send it to the Frame server. The check whether it’s a valid request (ie. fid 4286 pressing buttonIndex 1 on a specific cast), we need to verify the request against the Hub.
Copy
Ask AI
const result = await client.validateFrameAction({ messageBytesInHex: payload.trustedData.messageBytes,});console.log(result);
And that’s it, a valid Frame action! You’ve successfully verified a frame action payload against the Hub with Neynar SDK. Note that frame payloads are only available in responses, not in initial requests. Attempts to fetch a payload during a request will result in an error. If you want to fetch cast while doing frame validation, refer to our How to get cast information from URL guide.