Farcaster Frames
Using the FDK to build frames
The FDK can be used to not only create frames but also provide analytics through your Pinata account.
getFrameMetadata
You can use this function to easily create the Farcaster specific metadata needed for your frame.
The only required input is cid
or image
.
Params
buttons
- An array of button specifications (max 4). (Optional)image
- A string for a valid hosted image url.cid
- A string representing the cid of an IPFS pinned image.input
- A string representing the text displayed for text input. (Optional)post_url
- A string which contains a valid URL to send the Signature Packet to. (Optional)refresh_period
- A string representing the refresh period for the image used. (Optional)aspect_ratio
- A string representing the aspect ratio for the image used. (Optional)state
- An object (e.g. JSON) representing the state data for the frame. (Optional)
Note: state should only be included in response frames, not initial frames.
Example Code
Response
Images for getFrameMetadata
There are two different ways to set the images of your frame metadata.
⚡️ Raw URL
⚡️ CID
Raw URL
Specify a hosted url image link.
CID
Specify a CID from your Pinata account.
convertUrlToIPFS
Uploads an image to IPFS from a url. This url may be passed to the getFrameMetadata
function.
Params
url
- A string for a valid hosted url image.
Example Code
Response
validateFrameMessage
Returns a Promise that indicates wether a message signature is valid by querying Pinata’s Farcaster hub.
Params
body
- An object representing the raw payload of an action frame produced by Farcaster.
Example Code
Response
getAddressForFid
Returns the connected Ethereum address for an FID.
Params
fid
- A number representing the fid of the user.
Example Code
Response
Frame Analytics
To get started visit the Integrations page by clicking on the profile button in the top right, then selecting Integrations.
Once there you can click on “Sign In” which will bring up a QR code you can scan with you phone.
Scanning the QR code with your phone should prompt you to open Warpcast where you can sign in and approve the integration.
In any of your POST endpoints for frames, you can send analytics like this:
sendAnalytics
Sends data to Pinata analytics for a specific frame.
Params
frame_data
- An object representing the raw payload of an action frame produced by Farcaster.frame_id
- A string representing the frame you want to track.custom_id
: A string representing a unique identifier to segment requests within the specified frame. (Optional)
Example Code
Response
After this is deployed you will see the analytics on the Frame Analytics Page.
Frog Analytics Plug-in 🐸
If you are using the Frog framework, you can utilize Pinata Frame analytics by importing our custom middleware function analyticsMiddleware
.
Pin Files from CLI
npx pin
Pin files directly from your src
folder using the pinata-fdk npx pin
command.
Create a pins
folder located under your src
folder
Add any images you want uploaded to IPFS!
Run the command:
Check your src/pins
folder for a pins_list.json
file. Here you can easily access your CID to input into getFrameMetadata
.