Provider Setup
Wrap your app with the embarkAI
Providerto 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
import type { ReactNode } from "react";
import type { ProviderConfig, CallbacksConfig } from "@embarkai/ui-kit";
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.
import { Provider } from "@embarkai/ui-kit";
function App({ children }: { children: React.ReactNode }) {
return (
<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",
},
network: {
name: "Lumia Prism",
symbol: "LUMIA",
chainId: 994873017,
rpcUrl: "https://mainnet-rpc.lumia.org",
forceChain: false,
},
preferedColorMode: "dark",
}}
>
{children}
</Provider>
);
}initialConfig is deep-merged with the defaults at runtime. The prop is typed as a shallow Partial<ProviderConfig>, so a section you touch must be complete (network needs name, symbol, chainId, rpcUrl; passkey needs enabled, showCreateButton, primaryButtonText; and so on).
callbacks
Type: CallbacksConfig
Event callbacks for wallet lifecycle events.
import type { WalletReadyStatus } from "@embarkai/ui-kit";
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:
| Section | Description |
|---|---|
passkey | Configure passkey (WebAuthn) authentication |
email | Configure email-based authentication |
social | Configure social login providers (Google, Telegram, etc.) |
wallet | Configure external wallet connection (RainbowKit/WalletConnect) |
network | Set default chain and force-chain behavior |
ui | UI customization options |
services | Override service URLs (advanced) |
features | Feature flags (e.g., mpcSecurity) |
translations | Custom i18n translations |
watchTokens | Custom ERC-20 tokens to track per chain |
kyc | KYC integration settings |
preferedColorMode | 'light', 'dark', or omit for auto |
External Wallet Mode
To enable WalletConnect / RainbowKit alongside embarkAI wallets, set wallet.enabled: true:
import { Provider } from "@embarkai/ui-kit";
function App({ children }: { children: React.ReactNode }) {
return (
<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.
| Mode | Description |
|---|---|
linked | External wallet is linked to a smart account (account abstraction). Default. |
direct | External wallet signs transactions directly (no AA). |
both | User chooses between linked and direct mode. |
Lifecycle
When the Provider mounts:
- Config merge —
initialConfigis deep-merged with defaults. - Iframe initialization — A secure iframe is loaded for MPC key operations (DKG, signing).
- Session hydration — Previous session is restored from localStorage if available.
- Chain setup — If
network.forceChainis set, the active chain is locked to the configuredchainId.
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 { config, updateConfig } = useProviderConfig();
const switchToMainnet = () => {
updateConfig({
network: { ...config.current.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>
);
}