Skip to content

Configuration Options

type configurationOptions =
  | {
      neynarApiKey?: string;
      airstackApiKey?: string;
      activeService?: "airstack" | "neynar";
      debug?: boolean;
      logLevel?: "info" | "warning" | "error" | "success";
      cacheTtl?: number;
      retries?: number;
      retryStrategy?: "normal" | "switch" | "switchTemp";
    }
  | undefined;
 
const sdkInstanceInstance = new uniFarcasterSdk(configurationOptions);

configurationOptions is an object that takes the properties below

Neynar Api Key

const sdkInstanceInstance = new uniFarcasterSdk({
  neynarApiKey: "NEYNAR_API_DOCS",
});

You'd need to get your api key from neynar

Airstack Api Key

const sdkInstanceInstance = new uniFarcasterSdk({
  airstackApiKey: "your-airstack-api-key",
});

You'd need to get your api key from airstack

Active Service

const sdkInstance = new uniFarcasterSdk({
  activeService: "airstack",
});

You can specify which of the services you want to use.
By default, it will set the active service depending on which of the api keys you provide.
This option is especially useful when you have both api keys provided.

Cache Time To Live

const sdkInstance = new uniFarcasterSdk({
  cacheTtl: 60 * 60 * 1000, // 1 hour
});

By default, all queries are cached for 1 hour before they expire and would hit the external services again. You can configure how long you want them to be cached for in milliseconds.

Retries

const sdkInstance = new uniFarcasterSdk({
  retries: 0,
});

By default on error, it returns the error and does not retry the query. You can configure how many times you want to retry the query before returning the error.

Retry Strategy

const sdkInstance = new uniFarcasterSdk({
  retryStrategy: "switch",
});

Retry Strategy determines how you want to retry the query. There's 3 modes:

normal

This is the default and it simply retries the query for the number of retries you have in your config using the same service as the initial request.

switch

In this strategy, it changes the active service each time it retries. This only works when you have both airstack and neynar api keys configured.

switchTemp

This strategy works the same as switch but the difference is after all retries are completed (or successful), it switches back to the original service.

Debug

When set to true, it would log all queries on the console. One way to use this is using the environment variable NODE_ENV=development

const debugMode = process.env.NODE_ENV === "development";
const sdkInstance = new uniFarcasterSdk({
  debug: debugMode,
});

Log Level

In debug mode, this restricts what type of queries are logged to the console. By default, it logs all queries. This configuration only has an effect when debug is set to true

const sdkInstance = new uniFarcasterSdk({
  logLevel: "info",
  //Only logs of level "info" would show up on the console
});

You can choose from info, warning, error and success

Example Instance

const sdkInstance = uniFarcasterSdk({
  neynarApiKey: "NEYNAR_API_DOCS",
  airstackApiKey: "your-airstack-api-key",
  activeService: "neynar",
  cacheTtl: 60 * 1 * 1000, // 1 Minute
  retries: 3,
  retryStrategy: "switchTemp",
  debug: true,
  logLevel: "success",
});

Reference

PropertyTypeRequiredDescription
neynarApiKeystringoptionalApi key from neynar
airstackApiKeystringoptionalApi key from airstack
activeService'airstack' | 'neynar'optionalThe active service to use. Only has effect if both neynarApiKey and airstackApiKey are provided.
debugbooleanoptional. Default: falseLogs queries, cache and retry information when set to true
logLevel'info' | 'warning' | 'error' | 'success'optional. Default: undefinedThe log level to use. Only has effect when debug is set to true
cacheTtlnumberoptional. Defaults: 1 hourThe amount of time in milliseconds before invalidating a query
retriesnumberoptional. Default: 0The number of retries to do before returning the error.
retryStrategy'normal' | 'switch' | 'switchTemp'optional. Default: normalThe retry strategy to use.