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.
Import
import { GlyphProvider } from "@use-glyph/sdk-react";Usage
import { GlyphProvider, StrategyType } from "@use-glyph/sdk-react";
import { PrivyProvider } from "@privy-io/react-auth";
import { WagmiProvider, createConfig } from "@privy-io/wagmi";
import { http } from "viem";
import { apeChain } from "@use-glyph/sdk-react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
// Configure wagmi
const config = createConfig({
chains: [apeChain],
transports: {
[apeChain.id]: http(),
},
});
const queryClient = new QueryClient();
function App() {
return (
<PrivyProvider appId="YOUR_PRIVY_APP_ID">
<QueryClientProvider client={queryClient}>
<WagmiProvider config={config}>
<GlyphProvider strategy={StrategyType.PRIVY}>
{/* Your app content and other Glyph components */}
<YourComponent />
</GlyphProvider>
</WagmiProvider>
</QueryClientProvider>
</PrivyProvider>
);
}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. 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.
() => 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 authenticatedbalances: Token balances object or null if not authenticatedrefreshBalances: Function to refresh balancesrefreshUser: Function to refresh user informationlogin: Function to initiate loginlogout: Function to initiate logoutsignMessage: Function to sign messagessendTransaction: Function to send transactionssymbol: Current chain's native token symbolhideWidget: Boolean to control widget visibility (only for EIP1193 strategy)glyphUrl: The base URL for the Glyph Widget API or the Glyph Portal/Dashboard. 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 { PrivyProvider } from "@privy-io/react-auth";
import { WagmiProvider, createConfig } from "@privy-io/wagmi";
import { ErrorBoundary } from "react-error-boundary";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
function ErrorFallback({ error }) {
return (
<div role="alert">
<p>Something went wrong with the Glyph Widget:</p>
<pre>{error.message}</pre>
</div>
);
}
function App() {
const queryClient = new QueryClient();
const config = createConfig({
chains: [apeChain],
transports: {
[apeChain.id]: http(),
},
});
return (
<PrivyProvider appId="YOUR_PRIVY_APP_ID">
<QueryClientProvider client={queryClient}>
<WagmiProvider config={config}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<GlyphProvider strategy={StrategyType.PRIVY}>
<YourComponent />
</GlyphProvider>
</ErrorBoundary>
</WagmiProvider>
</QueryClientProvider>
</PrivyProvider>
);
}