Last active
November 10, 2023 00:53
-
-
Save manan19/61689068bc8e14b47dccf70996510be5 to your computer and use it in GitHub Desktop.
Sample code to get casts by fid from your Neynar-hosted Farcaster hub using a secure client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { getSSLHubRpcClient } = require('@farcaster/hub-nodejs'); | |
const getCastsByFid = async (hubRpcEndpoint, fid) => { | |
let client = getSSLHubRpcClient(hubRpcEndpoint); | |
client.$.waitForReady(Date.now() + 2000, async (e) => { | |
if (e) { | |
console.error(`Failed to connect to ${hubRpcEndpoint}`); | |
} else { | |
console.log(`Connected to ${hubRpcEndpoint}`); | |
const castsResult = await client.getCastsByFid({ fid: fid }); | |
console.log(`${castsResult.value?.messages.length} casts for fid ${fid} from ${hubRpcEndpoint}`); | |
} | |
client.close(); | |
}); | |
}; | |
getCastsByFid('your-hub-id.hubs.neynar.com:2283', 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment