When onboarding users with embedded wallets, there are added steps needed that the above guide doesn’t list out yet. While we work on updating that guide, below unofficial steps from JP who onboarded users on their app using Neynar APIs and Privy wallets. Shoutout to JP Franeto for the write up! 🪐
<aside> 💡
Disclaimer: Neynar team hasn’t run the code below so use at your own discretion. We will put up our version on the official guide soon.
</aside>
This documentation outlines the process for creating a new Farcaster ID (FID) using the Privy x Neynar integration. It details the frontend and backend implementations required to register a user through their embedded wallet, which is created using Privy.
The complete implementation can be found in the following repositories:
Relevant CreateAccountModal
Component
The CreateAccountModal
is a React Native component that is used to register a new user on Farcaster.
Creating the Farcaster account
import { usePrivy } from "@privy-io/expo";
import { useSmartWallets } from "@privy-io/expo/smart-wallets";
const CreateAccountModal = () => {
const { client } = useSmartWallets();
const { user, isReady } = usePrivy();
const handleCreateAccount = async () => {
try {
if (user && client) {
const smartWallet = user.linked_accounts.find(
(account) => account.type === "smart_wallet"
);
if (!smartWallet?.address) {
throw new Error("Smart wallet not found");
}
const { data: payload } = await axios.post(
"<https://farcaster.anky.bot/create-new-fid>",
{
user_wallet_address: smartWallet?.address,
}
);
const signature = await client.signTypedData({
account: client.account,
domain: {
name: "Farcaster ID Registry",
version: "1",
chainId: 10, // Optimism
verifyingContract: "0x00000000fc6c5f01fc30151999387bb99a9f489b", // ID_REGISTRY_ADDRESS
},
types: {
Transfer: [
{ name: "fid", type: "uint256" },
{ name: "to", type: "address" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
],
},
message: {
fid: payload.new_fid,
to: smartWallet.address,
nonce: payload.nonce,
deadline: payload.deadline,
},
});
const res = await axios.post(
"<https://farcaster.anky.bot/create-new-fid-signed-message>",
{
deadline: Number(payload.deadline),
address: wallet.account?.address,
fid: payload.new_fid,
signature,
user_id: ankyUser?.id,
}
);
console.log("Registration successful:", res.data);
onClose();
}
} catch (error) {
console.error("Error creating Farcaster account:", error);
setError(error.message || "Failed to create Farcaster account");
}
};
};