Gathering detailed insights and metrics for pinata-fdk
Gathering detailed insights and metrics for pinata-fdk
Gathering detailed insights and metrics for pinata-fdk
Gathering detailed insights and metrics for pinata-fdk
npm install pinata-fdk
Typescript
Module System
Node Version
NPM Version
TypeScript (96.27%)
JavaScript (3.73%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
38 Stars
197 Commits
2 Forks
2 Watchers
28 Branches
4 Contributors
Updated on Mar 16, 2025
Latest Version
3.10.2
Package Id
pinata-fdk@3.10.2
Unpacked Size
182.87 kB
Size
36.49 kB
File Count
9
NPM Version
10.2.4
Node Version
20.11.1
Published on
May 05, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
An SDK to easily create Farcaster Frames, manage frame analytics and pin images to IPFS using Pinata.
View the full documentation here.
1npm i pinata-fdk
1yarn add pinata-fdk
If you want to leverage IPFS pinning capabilities, you must enter your Pinata JWT and a Pinata gateway during intialization.
1import { PinataFDK } from "pinata-fdk"; 2const fdk = new PinataFDK({ 3 pinata_jwt: "<YOUR_PINATA_JWT>", 4 pinata_gateway: "<YOUR_PINATA_GATEWAY>"}, 5);
If you are only using the frame metadata functionality, you do not need to enter your credentials.
1import { PinataFDK } from "pinata-fdk"; 2const fdk = new PinataFDK();
The FDK makes it easy to give your Farcaster app write access for users so you can do things like sending casts or following other users. To get a better concept of the flow of Farcaster Auth, check out the guide here.
createSigner
This function will create a signer with Farcaster Auth, sign the key with your Farcaster App mnemonic phrase and FID, then send a request to Warpcast to register the signer. For more info on those please see these docs.
In order to use it make sure the mnemonic and FID are included with the PinataFDK instance.
1import { PinataFDK } from "pinata-fdk" 2 3const fdk = new PinataFDK({ 4 pinata_jwt: 'YOUR_PINATA_JWT', 5 pinata_gateway: 'YOUR_GATEWAY', 6 app_fid: 'APP_FID', 7 app_mnemonic: 'APP_MNEMONIC' 8})
1import { PinataFDK } from "pinata-fdk" 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6 app_fid: `${process.env.APP_FID}` 7 app_mnemonic: `${process.env.FARCASTER_DEVELOPER_MNEMONIC}` 8}) 9 10const signerData: WarpcastPayload = await fdk.createSigner()
After creating the signer the user would visit the signerData.deep_link_url
which would open Warpcast on their account to approve the signer. The user will have to pay warps since it is not sponsored.
1{ 2 signer_id: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 3 token: "0xe3bffad26b16cf825f3d062d", 4 deep_link_url: "farcaster://signed-key-request?token=0xe3bffad26b16cf825f3d062d", 5 status: "pending_approval" 6}
createSponsoredSigner
Sponsored signers is very similar to createSigner
except the end user will not have to pay warps to approve the signer. However there may be limits to how many sponsored signers you can use based on your Pinata plan. You still need the app_mnemonic
to sign the key being used.
1import { PinataFDK } from "pinata-fdk" 2 3const fdk = new PinataFDK({ 4 pinata_jwt: 'YOUR_PINATA_JWT', 5 pinata_gateway: 'YOUR_GATEWAY', 6 app_fid: 'APP_FID', 7 app_mnemonic: 'APP_MNEMONIC' 8})
1import { PinataFDK } from "pinata-fdk" 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6 app_fid: `${process.env.APP_FID}`, 7 app_mnemonic: `${process.env.FARCASTER_DEVELOPER_MNEMONIC}` 8}) 9 10const signerData: WarpcastPayload = await fdk.createSponsoredSigner()
After creating the signer the user would visit the signerData.deep_link_url
which would open Warpcast on their account to approve the signer. Since it is sponsored the user will not have to pay warps to sign in, however it will show Pinata as the app.
1{ 2 signer_id: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 3 token: "0x21658c8fa560aca0f35a5e4a", 4 deep_link_url: "farcaster://signed-key-request?token=0x21658c8fa560aca0f35a5e4a", 5 status: "pending_approval" 6}
pollSigner
After creating a signer and giving the user the deep_link_url
you will want to poll the signer to see if they have approved it and record the response to your account.
pollSigner
takes a parameter of token
which is provided in either createSigner
or createSponsoredSigner
.
1import { PinataFDK } from "pinata-fdk" 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6 app_fid: `${process.env.APP_FID}` 7}) 8 9const pollData = await fdk.pollSigner("0x21658c8fa560aca0f35a5e4a")
1{ 2 token: "0x321bbb927d9009232a7c26d6", 3 deeplinkUrl: "farcaster://signed-key-request?token=0x321bbb927d9009232a7c26d6", 4 key: "0x858e9ed1af97ec0c1cf06e7d769a2bca9ec324c152f320ee34b253af27b486f4", 5 requestFid: 20918, 6 state: "pending", 7 isSponsored: false 8}
getSigner
After you have created a signer and it has been polled as complete, you can fetch the signer at any time using getSigner
1import { PinataFDK } from "pinata-fdk" 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6 app_fid: `${process.env.APP_FID}` 7}) 8 9const pollData = await fdk.getSigner(6023)
1{ 2 signers: [ 3 { 4 id: 57, 5 signer_uuid: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 6 fid: 6023, 7 public_key: "dad973170c63739f7c812d188fab1df074eb1cd48facf6556e2ef9cbb76b4c18", 8 signer_approved: true, 9 revoked: false 10 } 11 ], 12 next_page_token: "eyJvZmZzZXQiOiI1NyJ9" 13}
These methods can be used to create casts, react to them, or even follow users. All of them require a signerId
which is a result of using Farcaster Auth, as well as the PinataFDK initialization with a Pinata JWT.
All of these methods also return the same response, which is the direct response from the Pinata Hub.
1type CastResponse = { 2 data: { 3 type: string; 4 fid: number; 5 timestamp: number; 6 network: string; 7 castAddBody: { 8 embedsDeprecated: any[]; 9 mentions: any[]; 10 text: string; 11 mentionsPositions: any[]; 12 embeds: any[]; 13 }; 14 }; 15 hash: string; 16 hashScheme: string; 17 signature: string; 18 signatureScheme: string; 19 signer: string; 20 dataBytes: string; 21};
sendCast
With the sendCast
method you can effortlessly post to Farcaster using a signerId
.
signerId
and the castAddBody
which follows the Farcaster Hub standard for sending casts.1type CastRequest = { 2 signerId: string; 3 castAddBody: CastBody; 4} 5 6type CastBody = { 7 embedsDeprecated?: string[]; 8 mentions?: number[]; 9 parentCastId?: CastId | null; 10 parentUrl?: string | null; 11 text?: string | null; 12 mentionsPositions?: number[] | null; 13 embeds?: Embed[] | null; 14} 15 16type CastId = { 17 fid: number; 18 hash: string; 19} 20 21type Embed = { 22 url?: string | null; 23 castId?: CastId | null; 24}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const res: CastResponse = await fdk.sendCast({ 9 castAddBody: { 10 text: "Hello World from !", 11 mentions: [6023], 12 mentionsPositions: [18], 13 parentUrl: "https://warpcast.com/~/channel/pinata", 14 embeds: [ 15 { 16 url: "https://pinata.cloud" 17 }, 18 { 19 castId: { 20 fid: 6023 21 hash: "0xcae8abd9badbb60c9b610ec264f42ed9f1785c6f", 22 } 23 } 24 ], 25 parentCastId: { 26 fid: 6023, 27 hash: "0xcae8abd9badbb60c9b610ec264f42ed9f1785c6f" 28 } 29 }, 30 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1" 31});
deleteCast
This method can delete a cast with a provided target hash.
1type CastDelete = { 2 hash: string; 3 signerId: string; 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const deleteReq: CastResponse = await fdk.deleteCast({ 9 hash: "0x490889854a4f3233433b1ad0560f016f04feeeff", 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
likeCast
This method can like a cast based on the provided target hash.
1type LikeCast = { 2 hash: string, 3 signerId: string 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const likeReq: CastResponse = await fdk.likeCast({ 9 hash: "0x490889854a4f3233433b1ad0560f016f04feeeff", 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
unlikeCast
If a cast is already liked by the user, this method will unlike it.
1type LikeCast = { 2 hash: string, 3 signerId: string 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const unlikeReq: CastResponse = await fdk.unlikeCast({ 9 hash: "0x490889854a4f3233433b1ad0560f016f04feeeff", 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
recastCast
This method will recast a cast based on the target hash.
1type RecastCast = { 2 hash: string; 3 signerId: string; 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const recastCastReq: CastResponse = await fdk.recastCast({ 9 hash: "0x490889854a4f3233433b1ad0560f016f04feeeff", 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
removeRecast
Works just like recastCast
but removes an existing recast based on a hash of the target cast.
1type RecastCast = { 2 hash: string; 3 signerId: string; 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const removeRecastReq: CastResponse = await fdk.removeRecast({ 9 hash: "0x490889854a4f3233433b1ad0560f016f04feeeff", 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
followUser
Follows a target user based on their FID.
1type FollowUser = { 2 fid: number; 3 signerId: string; 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const followUserReq: CastResponse = await fdk.followUser({ 9 fid: 6023, 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
unfollowUser
Unfollows a user that the signer is already following.
1type FollowUser = { 2 fid: number; 3 signerId: string; 4}
1import { CastResponse, PinataFDK } from "pinata-fdk"; 2 3const fdk = new PinataFDK({ 4 pinata_jwt: `${process.env.PINATA_JWT}`, 5 pinata_gateway: "", 6}); 7 8const unfollowUserReq: CastResponse = await fdk.unfollowUser({ 9 fid: 6023, 10 signerId: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1", 11};
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
.
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.
1type FrameHTMLType = { 2 buttons?: [FrameButtonMetadata, ...FrameButtonMetadata[]]; 3 image?: {url: string}; 4 cid?: string; 5 input?: FrameInputMetadata; 6 post_url?: string; 7 refresh_period?: number; 8 aspect_ratio?: "1.91:1" | "1:1", 9 state?: object 10} & ( 11 { image: {url: string}}| { cid: string } 12);
1type FrameButtonMetadata = { 2 label: string; 3 action?: "post" | "post_redirect" | "mint" | "link" | "tx"; 4 target?: string; 5}
1type FrameInputMetadata = { 2 text: string; 3};
1 const frameMetadata = fdk.getFrameMetadata({ 2 post_url: `<YOUR_DOMAIN>/api/test`, 3 input: {text: "Hello, world!"}, 4 aspectRatio: "1.91:1", 5 buttons: [ 6 { label: 'Click me', action: 'post'}, 7 { label: 'Button 2', action: "post_redirect"}, 8 { label: 'Button 3', action: "mint" }, 9 { label: 'Button 4', action: "link" }, 10 ], 11 cid: "<YOUR_CID>", 12 state: {counter: 1} 13 });
1<meta name="fc:frame" content="vNext"> 2<meta name="og:image" content="https://<YOUR_GATEWAY>/ipfs/<YOUR_CID>"> 3<meta name="fc:frame:image" content="https://<YOUR_GATEWAY>/ipfs/<YOUR_CID>"> 4<meta name="fc:frame:aspectRatio" content="1.91:1"> 5<meta name="fc:frame:input:text" content="Hello, world!"> 6<meta name="fc:frame:button:1" content="Click me"> 7<meta name="fc:frame:button:1:action" content="post"> 8<meta name="fc:frame:button:2" content="Button 2"> 9<meta name="fc:frame:button:2:action" content="post_redirect"> 10<meta name="fc:frame:button:3" content="Button 3"> 11<meta name="fc:frame:button:3:action" content="mint"> 12<meta name="fc:frame:button:4" content="Button 4"> 13<meta name="fc:frame:button:4:action" content="link"> 14<meta name="fc:frame:post_url" content="<YOUR_DOMAIN>/api/test"> 15<meta name="fc:frame:state" content="%7B%22counter%22%3A1%7D">
getFrameMetadata
There are two different ways to set the images of your frame metadata.
⚡️ Raw URL
⚡️ CID
Specify a hosted url image link.
1const frameMetadata = fdk.getFrameMetadata({ 2 image: { url: "<YOUR_URL>"} 3 });
Specify a CID from your Pinata account.
1const frameMetadata = fdk.getFrameMetadata({ 2 cid: "QmX63EYiDk9cExrv4GDmZ5soJKkgqoUJv9LbtPyugLBtV2" 3 }); 4 5//Must insert Pinata credentials when intializing SDK.
convertUrlToIPFS
Uploads an image to IPFS from a url. This url may be passed to the getFrameMetadata
function.
url
- A string for a valid hosted url image.1 const ipfsUrl = await fdk.convertUrlToIPFS("https://example.com"); 2 const frameMetadata = fdk.getFrameMetadata({ 3 image: { url: ipfsUrl} 4 });
1https://<YOUR_GATEWAY>/ipfs/<YOUR_CID>
validateFrameMessage
Returns a Promise that indicates wether a message signature is valid by querying Pinata's Farcaster hub.
body
- An object representing the raw payload of an action frame produced by Farcaster.{
untrustedData: {
fid: 2,
url: "https://fcpolls.com/polls/1",
messageHash: "0xd2b1ddc6c88e865a33cb1a565e0058d757042974",
timestamp: 1706243218,
network: 1,
buttonIndex: 2,
inputText: "hello world", // "" if requested and no input, undefined if input not requested
castId: {
fid: 226,
hash: "0xa48dd46161d8e57725f5e26e34ec19c13ff7f3b9",
},
},
trustedData: {
messageBytes: "d2b1ddc6c88e865a33cb1a565e0058d757042974...",
},
};
1const { isValid, message } = await fdk.validateFrameMessage(body);
1{ 2 isValid: true, 3 message: { 4 data: { 5 type: 13, 6 fid: 15974, 7 timestamp: 98469569, 8 network: 1, 9 castAddBody: undefined, 10 castRemoveBody: undefined, 11 reactionBody: undefined, 12 verificationAddAddressBody: undefined, 13 verificationRemoveBody: undefined, 14 userDataBody: undefined, 15 linkBody: undefined, 16 usernameProofBody: undefined, 17 frameActionBody: [Object] 18 }, 19 hash: <Buffer 46 f2 c3 eb ee 56 92 4f 14 47 2e f0 22 de 41 b6 26 52 a8 4d>, 20 hashScheme: 1, 21 signature: <Buffer 7a a0 5e b1 5a f9 59 a7 08 e9 d0 19 d2 24 47 f7 4b 15 d8 70 a8 fb 7e 36 f1 b6 06 14 c2 63 db 7f eb 98 4c 8a e7 98 5c 0d 72 27 04 f3 e9 19 08 10 e7 e9 ... 14 more bytes>, 22 signatureScheme: 1, 23 signer: <Buffer 1d 46 b7 63 1c 6f 15 7b 86 3a c1 9a 64 cd ba 7e b1 cc 2a cb 81 53 37 99 e8 69 e1 49 11 c4 81 4e>, 24 dataBytes: undefined 25 } 26}
getAddressForFid
Returns the connected Ethereum address for an FID.
fid
- A number representing the fid of the user.1const address = await fdk.getAddressForFid(15974);
"0x9b7c18a71a98acd2f1271e2d1fe63750a70bc52b"
getUserByFid
Returns the user datadata for an FID.
fid
- A number representing the fid of the user.1const userData = await fdk.getUserByFid(20591);
{
fid: 20591,
username: 'kyletut',
pfp: 'https://i.imgur.com/TLMFnH6.jpg',
bio: 'Everyone is from somewhere. Cofounder and CEO of Pinata. https://www.pinata.cloud/farcaster'
}
To get started visit the Integrations page by clicking on the profile button in the top right, then selecting Integrations.
Note: You must have Warpcast integrated in the web app to use this functionality.
In any of your POST endpoints for frames, you can send analytics like this:*
sendAnalytics
Sends data to Pinata analytics for a specific frame.
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)1// This should be the raw payload from the frame action 2const frame_data = { 3 untrustedData: { 4 fid: 2, 5 url: "https://fcpolls.com/polls/1", 6 messageHash: "0xd2b1ddc6c88e865a33cb1a565e0058d757042974", 7 timestamp: 1706243218, 8 network: 1, 9 buttonIndex: 2, 10 inputText: "hello world", // "" if requested and no input, undefined if input not requested 11 castId: { 12 fid: 226, 13 hash: "0xa48dd46161d8e57725f5e26e34ec19c13ff7f3b9", 14 }, 15 }, 16 trustedData: { 17 messageBytes: "d2b1ddc6c88e865a33cb1a565e0058d757042974...", 18 }, 19}; 20const frame_id = "my-unique-frame-name" 21const custom_id = "my_custom_id" 22 23 24await fdk.sendAnalytics(frame_id, frame_data, custom_id)
{success: true}
After this is deployed you will see the analytics on the Frame Analytics Page.
If you are using the Frog framework, you can utilize Pinata Frame analytics by importing our custom middleware function analyticsMiddleware
.
1import { PinataFDK } from "pinata-fdk"; 2const fdk = new PinataFDK({ 3 pinata_jwt: "<YOUR_PINATA_JWT>", 4 pinata_gateway: "<YOUR_PINATA_GATEWAY>"}, 5); 6 7const app = new Frog({ 8 basePath: '/api', 9 // hubApiUrl: "https://hub.pinata.cloud" 10}) 11 12app.use("/", fdk.analyticsMiddleware({ frameId: "frame_id", customId: "custom_id"}));
Pin files directly from your src
folder using the pinata-fdk npx pin
command.
Create a pins
folder located under your src
folder
1src 2-pins/
Add any images you want uploaded to IPFS!
1src 2-pins/ 3--image.png
Run the command:
1npx pin <YOUR_PINATA_JWT>
Check your src/pins
folder for a pins_list.json
file. Here you can easily access your CID to input into getFrameMetadata
.
No vulnerabilities found.
No security vulnerabilities found.