fix: update custody address lookup to use free api

This commit is contained in:
lucas-neynar 2025-04-29 13:10:27 -07:00
parent eba6b89593
commit 40e40543cd
No known key found for this signature in database
4 changed files with 9 additions and 35 deletions

View File

@ -60,34 +60,6 @@ async function queryNeynarApp(apiKey) {
}
}
async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
if (!apiKey) {
throw new Error('Neynar API key is required');
}
const lowerCasedCustodyAddress = custodyAddress.toLowerCase();
const response = await fetch(
`https://api.neynar.com/v2/farcaster/user/bulk-by-address?addresses=${lowerCasedCustodyAddress}&address_types=custody_address`,
{
headers: {
'accept': 'application/json',
'x-api-key': apiKey
}
}
);
if (!response.ok) {
throw new Error(`Failed to lookup FID: ${response.statusText}`);
}
const data = await response.json();
if (!data[lowerCasedCustodyAddress]?.length && !data[lowerCasedCustodyAddress][0].custody_address) {
throw new Error('No FID found for this custody address');
}
return data[lowerCasedCustodyAddress][0].fid;
}
// Export the main CLI function for programmatic use
export async function init() {
printWelcomeMessage();

View File

@ -1,6 +1,6 @@
{
"name": "@neynar/create-farcaster-mini-app",
"version": "1.2.16",
"version": "1.2.17",
"type": "module",
"private": false,
"access": "public",

View File

@ -20,9 +20,10 @@ async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
if (!apiKey) {
throw new Error('Neynar API key is required');
}
const lowerCasedCustodyAddress = custodyAddress.toLowerCase();
const response = await fetch(
`https://api.neynar.com/v2/farcaster/user/custody-address?custody_address=${custodyAddress}`,
`https://api.neynar.com/v2/farcaster/user/bulk-by-address?addresses=${lowerCasedCustodyAddress}&address_types=custody_address`,
{
headers: {
'accept': 'application/json',
@ -36,11 +37,11 @@ async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
}
const data = await response.json();
if (!data.user?.fid) {
if (!data[lowerCasedCustodyAddress]?.length || !data[lowerCasedCustodyAddress][0].custody_address) {
throw new Error('No FID found for this custody address');
}
return data.user.fid;
return data[lowerCasedCustodyAddress][0].fid;
}
async function loadEnvLocal() {

View File

@ -28,9 +28,10 @@ async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
if (!apiKey) {
throw new Error('Neynar API key is required');
}
const lowerCasedCustodyAddress = custodyAddress.toLowerCase();
const response = await fetch(
`https://api.neynar.com/v2/farcaster/user/custody-address?custody_address=${custodyAddress}`,
`https://api.neynar.com/v2/farcaster/user/bulk-by-address?addresses=${lowerCasedCustodyAddress}&address_types=custody_address`,
{
headers: {
'accept': 'application/json',
@ -44,11 +45,11 @@ async function lookupFidByCustodyAddress(custodyAddress, apiKey) {
}
const data = await response.json();
if (!data.user?.fid) {
if (!data[lowerCasedCustodyAddress]?.length || !data[lowerCasedCustodyAddress][0].custody_address) {
throw new Error('No FID found for this custody address');
}
return data.user.fid;
return data[lowerCasedCustodyAddress][0].fid;
}
async function generateFarcasterMetadata(domain, fid, accountAddress, seedPhrase, webhookUrl) {