From 40e40543cd9213412d4863a437afb8de137de2c2 Mon Sep 17 00:00:00 2001 From: lucas-neynar Date: Tue, 29 Apr 2025 13:10:27 -0700 Subject: [PATCH] fix: update custody address lookup to use free api --- bin/init.js | 28 ---------------------------- package.json | 2 +- scripts/build.js | 7 ++++--- scripts/deploy.js | 7 ++++--- 4 files changed, 9 insertions(+), 35 deletions(-) diff --git a/bin/init.js b/bin/init.js index 7f7074d..febbf61 100644 --- a/bin/init.js +++ b/bin/init.js @@ -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(); diff --git a/package.json b/package.json index 4efd334..db3f686 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@neynar/create-farcaster-mini-app", - "version": "1.2.16", + "version": "1.2.17", "type": "module", "private": false, "access": "public", diff --git a/scripts/build.js b/scripts/build.js index 43ebb80..ebab645 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -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() { diff --git a/scripts/deploy.js b/scripts/deploy.js index 5d0cfd2..b746fd7 100755 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -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) {