Skip to main content
This example will showcase how to read data from the Farcaster network using the official hub-nodejs in typescript. We will create a simple feed of casts from a list of FIDs and display them in reverse chronological order.

Installation

Create an empty typescript project and install the hub-nodejs package

1. Create a client

First, let’s set up some constants and create a client to connect to the hub.

2. Cache the fnames for the FIDs

Query the UserData for the provided FIDs, so we can show friendly usernames. Cache them for later.

3. Fetch top level casts

Query the hub for all casts for each FID, sorted in reverse chronological order and then filter to only the top level casts.

4. Function to pretty print a cast

The raw cast data is not very readable. We’ll write a function to convert the timestamp to a human readable format, and also resolve any mentions (only stored as fids and their location within the cast) to their fnames.

5. Sort and print the casts

Finally, we can sort the casts by timestamp again (so they are interleaved correctly) and print them out.

Full example

See full example here