Skip to Content
🌐 Frontend SDKProvider Setup

Provider Setup

Wrap your app with the EmbarkAI Provider to enable wallet functionality.

The Provider component is the root of every EmbarkAI integration. It initializes the wagmi client, sets up the secure MPC iframe for key operations, manages session state, and provides configuration to all child components and hooks.

Import

import { Provider } from '@embarkai/ui-kit'

Basic Usage

import { Provider, ConnectWalletButton } from '@embarkai/ui-kit' function App() { return ( <Provider projectId="your-project-id"> <ConnectWalletButton /> {/* Your application */} </Provider> ) }

Props

interface ProviderProps { children: ReactNode projectId?: string initialConfig?: Partial<ProviderConfig> callbacks?: CallbacksConfig }

projectId

Type: string

Your project identifier from the EmbarkAI Dashboard . This is required for the Provider to connect to EmbarkAI services.

initialConfig

Type: Partial<ProviderConfig>

Optional configuration object to customize authentication methods, network settings, UI behavior, and more.

<Provider projectId="your-project-id" initialConfig={{ passkey: { enabled: true, showCreateButton: true, primaryButtonText: 'Sign in with Passkey', }, email: { enabled: true, placeholder: 'Enter your email', buttonText: 'Continue with Email', verificationTitle: 'Verify your email', }, social: { enabled: true, providers: [ // Configured automatically by default ], }, network: { chainId: 994873017, // Lumia Mainnet forceChain: false, }, preferedColorMode: 'dark', }} > {children} </Provider>

callbacks

Type: CallbacksConfig

Event callbacks for wallet lifecycle events.

interface CallbacksConfig { onConnecting?: (payload: { method: 'passkey' | 'email' | 'social' | 'wallet' provider?: string }) => void onConnect?: (payload: { address: `0x${string}` session: any }) => void onAccount?: (payload: { userId?: string | null address?: `0x${string}` | null session?: any hasKeyshare?: boolean }) => void onAccountUpdate?: (payload: { providers?: Array<any> }) => void onDisconnect?: (payload: { address?: `0x${string}` | null userId?: string | null }) => void onError?: (payload: { error: Error code?: string message: string }) => void onChainChange?: (payload: { chainId: number previousChainId: number }) => void onWalletReady?: (status: WalletReadyStatus) => void }

Configuration Reference

The ProviderConfig object supports these top-level sections:

SectionDescription
passkeyConfigure passkey (WebAuthn) authentication
emailConfigure email-based authentication
socialConfigure social login providers (Google, Telegram, etc.)
walletConfigure external wallet connection (RainbowKit/WalletConnect)
networkSet default chain and force-chain behavior
uiUI customization options
servicesOverride service URLs (advanced)
featuresFeature flags (e.g., mpcSecurity)
translationsCustom i18n translations
watchTokensCustom ERC-20 tokens to track per chain
kycKYC integration settings
preferedColorMode'light', 'dark', or omit for auto

External Wallet Mode

To enable WalletConnect / RainbowKit alongside EmbarkAI wallets, set wallet.enabled: true:

<Provider projectId="your-project-id" initialConfig={{ wallet: { enabled: true, walletConnectProjectId: 'your-wc-project-id', mode: 'both', // 'linked' | 'direct' | 'both' }, }} > {children} </Provider>

When wallet.enabled is true, the Provider wraps children with RainbowKitProvider instead of the default WagmiProvider, enabling users to connect MetaMask, WalletConnect, and other external wallets.

ModeDescription
linkedExternal wallet is linked to a smart account (account abstraction). Default.
directExternal wallet signs transactions directly (no AA).
bothUser chooses between linked and direct mode.

Lifecycle

When the Provider mounts:

  1. Config mergeinitialConfig is deep-merged with defaults.
  2. Iframe initialization — A secure iframe is loaded for MPC key operations (DKG, signing).
  3. Session hydration — Previous session is restored from localStorage if available.
  4. Chain setup — If network.forceChain is set, the active chain is locked to the configured chainId.

When the Provider unmounts, the iframe manager is destroyed and resources are cleaned up.

Programmatic Config Updates

Use the useProviderConfig hook to update configuration at runtime without causing re-renders:

import { useProviderConfig } from '@embarkai/ui-kit' function Settings() { const { updateConfig, updateCallbacks } = useProviderConfig() const switchToMainnet = () => { updateConfig({ network: { chainId: 994873017 }, }) } return <button onClick={switchToMainnet}>Switch to Mainnet</button> }

Full Example

import { Provider, ConnectWalletButton } from '@embarkai/ui-kit' function App() { return ( <Provider projectId={process.env.NEXT_PUBLIC_EMBARK_PROJECT_ID!} initialConfig={{ passkey: { enabled: true, showCreateButton: true }, email: { enabled: true }, social: { enabled: true }, network: { chainId: 2030232745 }, // Lumia Testnet preferedColorMode: 'dark', }} callbacks={{ onConnect: ({ address }) => { console.log('Connected:', address) }, onError: ({ error, message }) => { console.error('Wallet error:', message, error) }, onWalletReady: (status) => { console.log('Wallet ready:', status.address, status.ready) }, }} > <header> <ConnectWalletButton /> </header> <main>{/* Your app */}</main> </Provider> ) }
Last updated on