Documentation Index
Fetch the complete documentation index at: https://docs.neynar.com/llms.txt
Use this file to discover all available pages before exploring further.
Pre-requisites
- Write access to a Snapchain instance
- Private key of an account key registered to an fid
- An Ethereum provider URL for OP Mainnet (e.g. via Alchemy, Infura or QuickNode).
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
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');
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
);
}