EIP-712 Farcaster Address Verification with Privy, Viem & Neynar
A step-by-step guide to verifying an Ethereum address on Farcaster using EIP-712, Privy RPC, Viem, and Neynar.
In this guide, you’ll learn how to perform a full EIP-712-based Ethereum address verification for Farcaster using:
- Privy RPC for secure off-chain signing
- Viem for EIP-712 hash computation and local signature verification
- Neynar API for submitting the verification to Farcaster
This tutorial is for advanced users who want to automate or deeply understand the Farcaster address verification process, including smart contract wallets.
Prerequisites
- Node.js ≥ 18
- A
.env
file with: - Install dependencies:
1. Setup & Imports
Start by importing dependencies and loading your environment variables:
2. Environment Variables & Constants
Define your configuration and constants:
3. EIP-712 Domain & Types
These are taken from Farcaster’s official EIP-712 spec:
We recommend using their package to import these but they’re providing for clarity.
4. Compose the Typed Data
Build the EIP-712 message to be signed. Make sure to include the correct chainId
and protocol
fields as these are different for smart account verification:
5. Compute the EIP-712 Hash
Use Viem’s hashTypedData
to get the digest for signing:
We generate the hashTypedData
directly due to an issue with privys typed data signers.
6. Sign via Privy RPC
Request a signature from Privy over the EIP-712 hash:
It is necessary to use secp256k1_sign
due to the aforementioned issue with their typed signers.
7. Local Signature Verification
Double-check the signature locally before submitting:
8. Submit to Neynar
Send the verification to Neynar for on-chain registration:
9. Error Handling
If anything fails, log and exit:
References & Further Reading
- EIP-712 Spec
- Farcaster Hub: validateVerificationAddEthAddressBody
- Farcaster Hub: verifyVerificationEthAddressClaimSignature
- Neynar Docs
- Privy Docs