Hubs are peer to peer servers that work together to download and serve both onchain and offchain data for the Farcaster network. They are key to keeping the network running and for allowing developers to build apps on top of Farcaster. Any time you need to access data from Farcaster such as messages, users, or events, you’ll need to access it in the form of a Hub. Sometimes this might take place in the raw Hub API or through an abstraction.

Pinata offers free to use Hubs that can be accessed via API:

hub.pinata.cloud

Or through gRPC:

hub-grpc.pinata.cloud
Pinata runs its Hubs through a proxy so the standard 2281 port is not required

Hub API

The Hub API can be used like any other API to fetch data like so:

curl --request GET \
  --url 'https://hub.pinata.cloud/v1/castsByFid?fid=6023&pageSize=10&reverse=true'

For more info on how to use the Hub API, check out our Hub API Reference.

Hub gRPC

The gRPC endpoint can be used inside the hub-nodejs library and provides a level of abstraction.

import { getSSLHubRpcClient } from '@farcaster/hub-nodejs';

const hubRpcEndpoint = 'hub-grpc.pinata.cloud';
const client = getSSLHubRpcClient(hubRpcEndpoint);

client.$.waitForReady(Date.now() + 5000, (e) => {
  if (e) {
    console.error(`Failed to connect to ${hubRpcEndpoint}:`, e);
    process.exit(1);
  } else {
    console.log(`Connected to ${hubRpcEndpoint}`);

    client.getCastsByFid({ fid: 6023 }).then((castsResult) => {
      castsResult.map((casts) => console.log(casts.messages));
      client.close();
    });
  }
});

Please consult the hub-nodejs documentation for more info on how to use it.