Skip to content

Instantly share code, notes, and snippets.

@manan19
Last active November 10, 2023 00:53
Show Gist options
  • Save manan19/61689068bc8e14b47dccf70996510be5 to your computer and use it in GitHub Desktop.
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
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