Implementation: Letβs use sdk to look up a user by their FID
Create index.ts file at root level
touch index.ts
Add the following code in index.ts
// index.tsimport{ NeynarAPIClient, Configuration, isApiErrorResponse }from"@neynar/nodejs-sdk";const config =newConfiguration({ apiKey:"<YOUR_API_KEY_HERE>",// Replace with your Neynar API Key.});const client =newNeynarAPIClient(config);(async()=>{try{const fid =19960;// 19960 (Required*) => fid of user we are looking forconst viewerFid =194;// 191 (Optional) => fid of the viewer// Get more info @ https://docs.neynar.com/reference/fetch-bulk-usersconst users =await client.fetchBulkUsers({ fids:[fid], viewerFid });// Stringify and log the responseconsole.log(JSON.stringify(users));}catch(error){// isApiErrorResponse can be used to check for Neynar API errorsif(isApiErrorResponse(error)){console.log("API Error", error.response.data);}else{console.log("Generic Error", error);}}})();
You should see a response like this. (You might not get a beautified/ formatted response since we JSON.stringify the response to log everything)
{"users":[{"object":"user","fid":19960,"username":"shreyas-chorge","display_name":"Shreyas","pfp_url":"https://i.imgur.com/LPzRlQl.jpg","custody_address":"0xd1b702203b1b3b641a699997746bd4a12d157909","profile":{"bio":{"text":"Everyday regular normal guy | π¨βπ» @neynar ..."},"location":{"latitude":19.22,"longitude":72.98,"address":{"city":"Thane","state":"Maharashtra","country":"India","country_code":"in"}}},"follower_count":250,"following_count":92,"verifications":["0xd1b702203b1b3b641a699997746bd4a12d157909","0x7ea5dada4021c2c625e73d2a78882e91b93c174c"],"verified_addresses":{"eth_addresses":["0xd1b702203b1b3b641a699997746bd4a12d157909","0x7ea5dada4021c2c625e73d2a78882e91b93c174c"],"sol_addresses":[]},"verified_accounts":null,"power_badge":false,"viewer_context":{"following":true,"followed_by":true,"blocking":false,"blocked_by":false}}]}