Neynar Documentation

Pre-requisites

To create a Verification proving ownership of an external Ethereum address, you can use an Eip712Signer to sign a verification message, and the makeVerificationAddEthAddress function to construct a message to send to a Hub.First, set up clients and account keys:

import {
  NobleEd25519Signer,
  ViemLocalEip712Signer,
  FarcasterNetwork,
  makeVerificationAddEthAddress,
} from '@farcaster/hub-nodejs';
import { createPublicClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { optimism } from 'viem/chains';

const publicClient = createPublicClient({
  chain: optimism,
  transport: http(),
});

const alice = privateKeyToAccount('0xab..12');
const eip712Signer = new ViemLocalEip712Signer(alice);

const ed25519Signer = new NobleEd25519Signer('0xcd..34');

Then create a verification signature using an Eip712Signer. You’ll need to query the latest blockhash on OP mainnet and include it in the signed message.

const latestBlock = await publicClient.getBlock();

const fid = 1n;
const network = FarcasterNetwork.MAINNET;
const address = alice.address;
const blockHash = latestBlock.hash;

const ethSignature = await eip712Signer.signVerificationEthAddressClaim({
  fid,
  address,
  network,
  blockHash,
});

Finally, use makeVerificationAddEthAddress to construct a Verification message you can send to a Hub.

if (ethSignature.isOk()) {
  const message = await makeVerificationAddEthAddress(
    {
      address,
      blockHash,
      ethSignature: ethSignature._unsafeUnwrap(),
    },
    { fid, network },
    ed25519Signer
  );
}

Full code example

const publicClient = createPublicClient({ chain: optimism, transport: http(), });

const alice = privateKeyToAccount('0xab..12'); const eip712Signer = new ViemLocalEip712Signer(alice);

const ed25519Signer = new NobleEd25519Signer('0xcd..34');

const latestBlock = await publicClient.getBlock();

const fid = 1n; const network = FarcasterNetwork.MAINNET; const address = alice.address; const blockHash = latestBlock.hash;

const ethSignature = await eip712Signer.signVerificationEthAddressClaim({ fid, address, network, blockHash, });

if (ethSignature.isOk()) { const message = await makeVerificationAddEthAddress( { address, blockHash, ethSignature: ethSignature._unsafeUnwrap(), }, { fid, network }, ed25519Signer ); }


Related topics

[Farcaster Address Verification with EIP-712](https://docs.neynar.com/docs/smart-account-verifications) [Messages](https://docs.neynar.com/snapchain/datatypes/messages) [SDK v1 to v2 migration guide](https://docs.neynar.com/reference/neynar-nodejs-sdk-v1-to-v2-migration-guide) [ETH Address FID Contract](https://docs.neynar.com/docs/verifications-contract) [Fetch verifications](https://docs.neynar.com/reference/fetch-verifications)