fhub is a library for interacting with a Farcaster Hub. It provides a client to connect to a Farcaster Hub and perform various actions such as retrieving and creating casts, following users, liking casts, and more.
To use fhub, install it as a dependency in your project:
npm install fhubHere is a basic example of how to use fhub:
-
Set up your environment variables:
RPC_URL: The URL of the Farcaster Hub RPC endpoint.FID: Your Farcaster ID.PRIVATE_KEY: Your private key in the format0x<private_key>.
-
Create a client and perform actions:
import { Actions, Client, Transport } from 'fhub';
const RPC_URL = process.env.RPC_URL ?? 'https://hub-grpc.pinata.cloud';
const FID = BigInt(process.env.FID);
const PRIVATE_KEY = process.env.PRIVATE_KEY as `0x${string}`;
const client = Client.create(
Transport.grpcNode({
baseUrl: RPC_URL,
httpVersion: '2',
}),
);
// Example: Get user data bio
const myBio = await Actions.UserData.getUserDataBio(client, { fid: 11517n });
console.log(myBio);
// Example: Create a cast
const message = await Actions.Cast.create(client, {
text: `Hello from fhub!`,
account: {
fid: FID,
privateKey: PRIVATE_KEY,
},
});
console.log(message);- Retrieve a cast:
Actions.Cast.getCast - Retrieve casts by FID:
Actions.Cast.getCastsByFid - Retrieve user data bio:
Actions.UserData.getUserDataBio - Create a cast:
Actions.Cast.create - Follow a user:
Actions.Follow.createByUsername - Like a cast:
Actions.Like.create - Recast:
Actions.Recast.create
The repository includes a playground for testing and experimenting with fhub. To run the playground:
- Navigate to the
playgrounddirectory. - Install dependencies:
npm install
- Run the playground:
npm run dev
For more detailed examples, refer to the playground/src/index.ts file in the repository.
Contributions are welcome! Please open an issue or submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.