Unique global key (e.g. 'synapseClient').
Function that creates the instance.
Optionaloptions: SingletonOptionsOptional version for cache invalidation.
A zero-arg getter that returns the singleton.
import { createSingleton } from '@oobe-protocol-labs/synapse-client-sdk/utils';
import { SynapseClient } from '@oobe-protocol-labs/synapse-client-sdk';
export const getSynapseClient = createSingleton('synapseClient', () =>
SynapseClient.fromEndpoint({ network: 'mainnet', region: 'US', apiKey: process.env.SYNAPSE_API_KEY! }),
);
// With version invalidation — bump to recreate:
export const getGateway = createSingleton('agentGateway', () =>
createAgentGateway(getSynapseClient(), config),
{ version: 4 },
);
Create an HMR-safe singleton accessor.
In Next.js (and other HMR-enabled environments) module scope is re-evaluated on every hot reload, destroying any
let/constsingleton. This helper stores the instance onglobalThisso it survives reloads.