Skip to content

Instantly share code, notes, and snippets.

@avneesh0612
Created April 17, 2024 12:12
Show Gist options
  • Save avneesh0612/65ca14d20549303d0a08da2daebb96cb to your computer and use it in GitHub Desktop.
Save avneesh0612/65ca14d20549303d0a08da2daebb96cb to your computer and use it in GitHub Desktop.
import { getSSLHubRpcClient, HubEventType } from "@farcaster/hub-nodejs";
const hubRpcEndpoint = "YOUR_GRPC_URL";
const client = getSSLHubRpcClient(hubRpcEndpoint);
client.$.waitForReady(Date.now() + 5000, async (e) => {
if (e) {
console.error(`Failed to connect to ${hubRpcEndpoint}:`, e);
process.exit(1);
} else {
console.log(`Connected to ${hubRpcEndpoint}`);
const subscribeResult = await client.subscribe({
eventTypes: [HubEventType.MERGE_MESSAGE],
});
if (subscribeResult.isOk()) {
const stream = subscribeResult.value;
for await (const event of stream) {
if (event.mergeMessageBody.message.data.type === 1) {
console.log(event.mergeMessageBody.message.data.castAddBody.text);
}
}
}
client.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment