Farcaster
Farcaster is a sufficiently decentralized social network whose core social graph is stored onchain. Privy enables your users to log in to your application using their Farcaster account. Privy uses a standard called Sign in with Farcaster (FIP-11) to issue a signature request to a user’s Farcaster account via the client a user has. Warpcast is currently supported.
Your application can even request permissions from the user to become a signer for their Farcaster account, allowing your application to engage with the Farcaster social graph on their behalf.
Interested in building a Farcaster frame? Check out our Farcaster frames recipe!
Privy currently only supports Farcaster login in React via the Privy UIs. To enable Farcaster login, you need to configure the Privy SDK with the farcaster
login method.
From there, you can prompt your users to authenticate via the login
method:
Privy currently only supports Farcaster login in React via the Privy UIs. To enable Farcaster login, you need to configure the Privy SDK with the farcaster
login method.
From there, you can prompt your users to authenticate via the login
method:
To authenticate a user via Farcaster (SIWF), use the loginWithFarcaster
method
from the useLoginWithFarcaster
hook.
Initializing the login flow
To initialize login, use the loginWithFarcaster
function from the useLoginWithFarcaster
hook to start the Farcaster login flow.
As a parameter to loginWithFarcaster
, you should pass an object containing:
Your app’s website. Described in SIWF spec as “Origin domain of app frontend.”
A URL path that Warpcast will automatically redirect to after successful authentication. This defaults to a link back to your app root, eg. '/'
, if not provided.
If true, the flow will only allow existing users to log in, preventing new account creation.
The interval in milliseconds which your app will poll a status endpoint to check if the user has successfully signed in using Warpcast.
The number of polling attempts that will be made to check for successful login.
If you pass in custom polling configuration, make sure to give the user enough time to go through the login process on Warpcast. The default values are pollIntervalMs = 1000
and pollAttempts = 10
giving the user 10 seconds to go through the login process. In our testing, this is usually enough time, but you may want to make it longer.
When this method is invoked, the user will be deeplinked to the Warpcast app on their device if they have it installed, or an installation page for the app. Within the Warpcast app, they can complete the login flow.
If loginWithFarcaster
succeeds, it will return a PrivyUser
object with details about the authenticated user.
Reasons loginWithFarcaster
might fail include:
- the network request fails
- the login attempt is made after the user is already logged in
- the user cancels the login flow after being linked out to Warpcast
- the user takes too long to login and the polling time expires
Tracking Flow State
Track the state of the Farcaster flow via the state
variable returned by the useLoginWithFarcaster
hook.
The current state of the Farcaster flow.
The error that occurred during the Farcaster flow (only present when status is ‘error’).
Usage: Conditional Rendering
Callbacks
You can optionally pass callbacks to the useLoginWithFarcaster
hook to run custom logic after a successful login or to handle errors.
onSuccess
Parameters
The user object returned after successful login.
Whether the user is a new user or an existing user.
onError
Parameters
The error that occurred during the Farcaster flow.