Sponsor signers

Sponsor it yourself or let Neynar pay for it

📘

This guide builds on Write data to Farcaster using Neynar managed signers. Useful to read that first if you haven't already.

There are two ways to sponsor a signer on behalf of a user. This saves the user from paying for it and increases conversion in your funnel. You have two options to sponsor:

  1. Let Neynar Sponsor It: You can choose to have Neynar sponsor the signer on your behalf, we will charge you compute units that correspond to the sponsorship fees.
  2. Sponsor it Yourself: You can sponsor the signer directly. Your application must be signed up on Warpcast and have warps ≥ 100

1. Let Neynar sponsor it

Set sponsored_by_neynar to true as shown below, the rest will remain the same as in the parent guide.

const options = { 
 sponsor: {
	sponsored_by_neynar: true
}};

const signedKey = await neynarClient.registerSignedKey(
    createSigner.signer_uuid,
    fid,
    deadline,
    signature,
    options
  );

Note:

When you see "sponsored by @your_app_fname" (@avneeshtest in this case) on the Warpcast screen, it's because you're signing a message. Even though it says "sponsored by @your_app_fname," the warps are being deducted from Neynar's account.

The signer is still branded under your name (@your_app_fname), Neynar is covering the costs and charging you compute units in the background. The user is unaware of Neynar and thinks your app is covering the costs.

2. Sponsor it with your app

You can do this very easily, just follow the steps below!

In the generate signature function add the following to generate a sponsorSignature:

 const sponsorSignature = await account.signMessage({
    message: { raw: sigHex },
  });

  sponsor = {
    signature: sponsorSignature,
    fid: FID,
  };

Then, add this sponsor object to the object we're returning like this:

  return { deadline, signature: sigHex, sponsor };

Finally, you can get the sponsor object from the generate_signature function and pass it in as an option in the registerSignedKey function like this:

  const { deadline, signature, sponsor } = await generate_signature(
    createSigner.public_key
  );

  if (deadline === 0 || signature === "") {
    throw new Error("Failed to generate signature");
  }

  const fid = await getFid();

  const options = sponsor ? { sponsor } : undefined;

  const signedKey = await neynarClient.registerSignedKey(
    createSigner.signer_uuid,
    fid,
    deadline,
    signature,
    options
  );

signedKey will have signer_approval_url. Make it available (either by creating a QR Code for the desktop application or allowing user to deeplink into warpcast by clicking on it in mobile device).

If you go ahead and try signing in now, it should show "Onchain fees sponsored by @xyz"