Skip to main content

Important Note

The Neynar Client Instantiation and API calls (fetchNonce and fetchSigners) should ideally be performed on the backend to protect your API key and maintain security.

Prerequisites

1

Ethereum-Enabled Browser

Browser Ensure you are using a browser with a wallet like MetaMask installed.
2

API Key

Obtain an API key from dev portal
3

Dependencies Installed

Install the required packages:

Code Breakdown and Steps

1

Import Required Libraries

The code starts by importing the necessary libraries:
2

Configure Neynar API Client

Set up the Neynar API client with your API key and base path. Note that this should ideally be done on the backend for security reasons:
3

Create the Wallet Client

The createWalletClient function initializes a wallet client using the viem library. It uses window.ethereum to connect to the browser’s wallet:
4

Create the SIWE Message

The createSiweMessage function generates a SIWE message with details such as domain, address, and nonce:
5

Sign and Verify the Message

The fetchSigners function retrieves the user’s Ethereum address, generates a SIWE message, signs it, and verifies the signature using the Neynar API.Note:
  1. Neynar API should ideally be accessed from the backend
  2. The address should be the custody_address of the farcaster account (Check custody_address in User API)
6

Execute the Function

Call the fetchSigners function and handle the response or errors:

Expected Output

For additional help, feel free to contact us.