GlyphProvider
The React context provider component that serves as a wrapper for implementing different wallet connection strategies. All other components and hooks must be used within this provider.
TIP
If you're using GlyphPrivyProvider or GlyphWalletProvider, you don't need to use GlyphProvider directly -- those providers wrap it internally and handle chain configuration for you.
Use GlyphProvider directly only when you need full control over the wagmi/query provider stack.
Import
import { GlyphProvider } from "@use-glyph/sdk-react";Usage
In v2.x, chains are configured dynamically. Use useGlyphConfigureDynamicChains to fetch the supported chains before creating your wagmi config:
import {
GlyphProvider,
useGlyphConfigureDynamicChains,
StrategyType,
} from "@use-glyph/sdk-react";
import { PrivyProvider } from "@privy-io/react-auth";
import { WagmiProvider, createConfig } from "@privy-io/wagmi";
import { http, Transport } from "viem";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useMemo } from "react";
const queryClient = new QueryClient();
function AppWithProviders({ children }: { children: React.ReactNode }) {
const { chains } = useGlyphConfigureDynamicChains();
const wagmiConfig = useMemo(() => {
if (chains.length === 0) return null;
return createConfig({
chains,
transports: chains.reduce((acc, chain) => {
acc[chain.id] = http();
return acc;
}, {} as Record<number, Transport>),
});
}, [chains]);
if (!wagmiConfig) return <div>Loading chains...</div>;
return (
<PrivyProvider appId="YOUR_PRIVY_APP_ID">
<QueryClientProvider client={queryClient}>
<WagmiProvider config={wagmiConfig}>
<GlyphProvider strategy={StrategyType.PRIVY}>
{children}
</GlyphProvider>
</WagmiProvider>
</QueryClientProvider>
</PrivyProvider>
);
}
function App() {
return (
<AppWithProviders>
<YourComponent />
</AppWithProviders>
);
}Props
StrategyTypeThe wallet connection strategy to use. Defaults to StrategyType.PRIVY. Available strategies:
StrategyType.PRIVY: Uses Privy for authentication and wallet managementStrategyType.EIP1193: Uses EIP-1193 compatible wallets
WalletClientTypeThe wallet client type to use. Read more about available wallet client types in the WalletClientType section.
booleanOptional. Only applicable when strategy is StrategyType.EIP1193. Whether to ask for a signature from the user after connecting. Set to false if you DO NOT intend to use the Glyph Widget or need the useGlyph hook's context to be authenticated. Defaults to true.
stringOptional. Override the Glyph API URL (e.g. for staging environments).
booleanOptional. Use the staging tenant instead of production.
() => voidOptional. A callback function that is called when the user logs in.
() => voidOptional. A callback function that is called when the user logs out.
Provider Nesting
The GlyphProvider must be nested within the following providers in this specific order:
PrivyProvider
└── QueryClientProvider
└── WagmiProvider
└── GlyphProvider
└── Your ComponentsContext Values
The GlyphProvider provides the following values to its children through React Context:
ready: Boolean indicating if the context is ready to be usedauthenticated: Boolean indicating if the user is authenticateduser: User information object or null if not authenticatedrefreshUser: Function to refresh user data from the Glyph APIbalances: Token balances object or null if not authenticatedrefreshBalances: Function to refresh token balancesnativeSymbol: Current chain's native token symbolhasBalances: Whether balances have been loadedisBalancesLoading: Whether a balance fetch is in progressfetchForAllNetworks: Whether multi-chain balance mode is activesetFetchForAllNetworks: Toggle multi-chain balance modesignMessage: Function to sign messages (returnsPromise<string>)signTypedData: Function to sign EIP-712 typed data (returnsPromise<string>)sendTransaction: Function to send transactions (returnsPromise<string>)login: Function to initiate loginlogout: Function to initiate logouthideWidget: Boolean to control widget visibility (only for EIP1193 strategy)glyphUrl: The base URL for the Glyph Widget API. If not overridden, uses the default URL.
These values can be accessed using the useGlyph hook.
Example with Error Handling
import { GlyphProvider, StrategyType } from "@use-glyph/sdk-react";
import { ErrorBoundary } from "react-error-boundary";
function ErrorFallback({ error }) {
return (
<div role="alert">
<p>Something went wrong with the Glyph Widget:</p>
<pre>{error.message}</pre>
</div>
);
}
// Inside your provider stack (see Usage above for full setup):
<ErrorBoundary FallbackComponent={ErrorFallback}>
<GlyphProvider strategy={StrategyType.PRIVY}>
<YourComponent />
</GlyphProvider>
</ErrorBoundary>