Untitled
unknown
plain_text
7 months ago
1.0 kB
14
Indexable
import {
createDefaultMetadataKeyInterceptor,
getInsecureHubRpcClient,
getSSLHubRpcClient,
} from '@farcaster/hub-nodejs';
const NEYNAR_DEVELOPER_API_KEY =
process.env.NEYNAR_DEVELOPER_API_KEY;
const testHub = async (hubRpcEndpoint, ssl) => {
const interceptors = [
createDefaultMetadataKeyInterceptor(
'x-api-key',
NEYNAR_DEVELOPER_API_KEY,
),
];
const options = {
interceptors,
};
const client = ssl
? getSSLHubRpcClient(hubRpcEndpoint, options)
: getInsecureHubRpcClient(hubRpcEndpoint, options);
const fid = 3;
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 });
console.log(
`${castsResult.value?.messages.length} casts for fid ${fid} from ${hubRpcEndpoint}`,
);
}
client.close();
});
};
testHub('hub-grpc-api.neynar.com', true);Editor is loading...
Leave a Comment