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.

import { PinataFDK } from "pinata-fdk"

const fdk = new PinataFDK({
  pinata_jwt: 'YOUR_PINATA_JWT',
  pinata_gateway: 'YOUR_GATEWAY',
  app_fid: 'APP_FID',
  app_mnemonic: 'APP_MNEMONIC'
})

Example

import { PinataFDK } from "pinata-fdk"

const fdk = new PinataFDK({
  pinata_jwt: `${process.env.PINATA_JWT}`,
  pinata_gateway: "",
  app_fid: `${process.env.APP_FID}`
  app_mnemonic: `${process.env.FARCASTER_DEVELOPER_MNEMONIC}`
})

const 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.

Response

{
  signer_id: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1",
  token: "0xe3bffad26b16cf825f3d062d",
  deep_link_url: "farcaster://signed-key-request?token=0xe3bffad26b16cf825f3d062d",
  status: "pending_approval"
}

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.

import { PinataFDK } from "pinata-fdk"

const fdk = new PinataFDK({
  pinata_jwt: 'YOUR_PINATA_JWT',
  pinata_gateway: 'YOUR_GATEWAY',
  app_fid: 'APP_FID',
  app_mnemonic: 'APP_MNEMONIC'
})

Example

import { PinataFDK } from "pinata-fdk"

const fdk = new PinataFDK({
  pinata_jwt: `${process.env.PINATA_JWT}`,
  pinata_gateway: "",
  app_fid: `${process.env.APP_FID}`,
  app_mnemonic: `${process.env.FARCASTER_DEVELOPER_MNEMONIC}`
})

const 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.

Response

{
  signer_id: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1",
  token: "0x21658c8fa560aca0f35a5e4a",
  deep_link_url: "farcaster://signed-key-request?token=0x21658c8fa560aca0f35a5e4a",
  status: "pending_approval"
}

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.

Params

pollSigner takes a parameter of token which is provided in either createSigner or createSponsoredSigner.

Example

import { PinataFDK } from "pinata-fdk"

const fdk = new PinataFDK({
  pinata_jwt: `${process.env.PINATA_JWT}`,
  pinata_gateway: "",
  app_fid: `${process.env.APP_FID}`
})

const pollData = await fdk.pollSigner("0x21658c8fa560aca0f35a5e4a") 

Returns

{
  token: "0x321bbb927d9009232a7c26d6",
  deeplinkUrl: "farcaster://signed-key-request?token=0x321bbb927d9009232a7c26d6",
  key: "0x858e9ed1af97ec0c1cf06e7d769a2bca9ec324c152f320ee34b253af27b486f4",
  requestFid: 20918,
  state: "pending",
  isSponsored: false
}

getSigner

After you have created a signer and it has been polled as complete, you can fetch the signer at any time using getSigner

Params

  • fid - A number/integer of the FID you want to query. (Optional)

Example

import { PinataFDK } from "pinata-fdk"

const fdk = new PinataFDK({
  pinata_jwt: `${process.env.PINATA_JWT}`,
  pinata_gateway: "",
  app_fid: `${process.env.APP_FID}`
})

const pollData = await fdk.getSigner(6023) 

Returns

{
  signers: [
    {
      id: 57,
      signer_uuid: "ba2d9f6d-7514-4967-8b52-5a040b7da4a1",
      fid: 6023,
      public_key: "dad973170c63739f7c812d188fab1df074eb1cd48facf6556e2ef9cbb76b4c18",
      signer_approved: true,
      revoked: false
    }
  ],
  next_page_token: "eyJvZmZzZXQiOiI1NyJ9"
}