Add to Existing Project
By the end of this tutorial, you’ll have embedded smart wallets with authentication integrated into your existing React application, allowing users to login without seed phrases and perform gasless transactions.
This tutorial assumes you’re using a React application with Next.js app router. If you’re using a different setup, the core concepts remain the same but you may need to adapt the provider setup to your framework.
1. Install the packages
Install the React and Infra packages from Account Kit along with required dependencies.
Prerequisites
- React 18+
- TypeScript 5+
Set up Tailwind CSS
Create a postcss.config.mjs
file and add the Tailwind plugin:
Create a global.css
file and import it in your app root:
Using Tailwind v3? You can skip the setup above since you’ve already configured it.
2. Get your API Key
-
Create an app in the Alchemy Dashboard
- Make sure your desired network is enabled under the Networks tab
-
Create a new configuration in your Smart Wallets Dashboard
- Apply the config to your app from step 1
- Enable the authentication methods you want (email, social login, etc.)
- For testing, use
http://localhost:3000
as your redirect URL
-
Copy your API key from the dashboard - you’ll need it for the next step
3. Configure your authentication and styling
Create two configuration files that will customize your authentication methods and UI styles.
Create your configuration files
- In your project root, create a
config.ts
file - In your project root, create a
tailwind.config.ts
file
You can customize these by visiting our demo app - use the interactive sandbox to explore different authentication methods and styling options. When ready, click ‘Code preview’ to export your customized configuration files.
Basic configuration example
Here’s a basic configuration to get you started:
tailwind.config.ts
Important: If your tailwind.config.ts
already contains any existing
config information, be sure to wrap it with withAccountKitUi
as shown above.
Don’t replace your existing config - just wrap it!
Update your global.css
to include the config:
Update your global.css file to include your tailwind.config.ts. (Skip this step if you’re still using Tailwind v3.)
config.ts
import { const createConfig: (props: CreateConfigProps, ui?: AlchemyAccountsUIConfig) => AlchemyAccountsConfigWithUIWraps the createConfig
that is exported from @aa-sdk/core
to allow passing an additional argument, the configuration object for the Auth Components UI (the modal and AuthCard).
createConfig, const cookieStorage: (config?: {
sessionLength?: number;
domain?: string;
}) => StorageFunction to create cookie based Storage
cookieStorage } from "@account-kit/react";
import { class QueryClientQueryClient } from "@tanstack/react-query";
import { const arbitrumSepolia: ChainarbitrumSepolia, function alchemy(config: AlchemyTransportConfig): AlchemyTransportCreates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.
alchemy } from "@account-kit/infra";
export const const config: AlchemyAccountsConfigWithUIconfig = function createConfig(props: CreateConfigProps, ui?: AlchemyAccountsUIConfig): AlchemyAccountsConfigWithUIWraps the createConfig
that is exported from @aa-sdk/core
to allow passing an additional argument, the configuration object for the Auth Components UI (the modal and AuthCard).
createConfig(
{
transport: AlchemyTransporttransport: function alchemy(config: AlchemyTransportConfig): AlchemyTransportCreates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.
alchemy({ apiKey: stringapiKey: "YOUR_API_KEY" }), // Replace with your API key
chain: Chainchain: const arbitrumSepolia: ChainarbitrumSepolia,
ssr?: boolean | undefinedEnable this parameter if you are using the config in an SSR setting (eg. NextJS) Turing this setting on will disable automatic hydration of the client store
ssr: true,
storage?: CreateStorageFn | undefinedstorage: const cookieStorage: (config?: {
sessionLength?: number;
domain?: string;
}) => StorageFunction to create cookie based Storage
cookieStorage,
enablePopupOauth: trueenablePopupOauth: true,
},
{
auth?: {
addPasskeyOnSignup?: boolean;
header?: React.ReactNode;
hideError?: boolean;
onAuthSuccess?: () => void;
sections: AuthType[][];
hideSignInText?: boolean;
} | undefinedauth: {
sections: AuthType[][]Each section can contain multiple auth types which will be grouped together and separated by an OR divider
sections: [
[{ type: "email"type: "email" }],
[
{ type: "passkey"type: "passkey" },
{ type: "social"type: "social", authProviderId: KnownAuthProviderauthProviderId: "google", mode: "popup"mode: "popup" },
],
],
addPasskeyOnSignup?: boolean | undefinedIf this is true, then auth components will prompt users to add a passkey after signing in for the first time
addPasskeyOnSignup: true,
},
},
);
export const const queryClient: QueryClientqueryClient = new new QueryClient(config?: QueryClientConfig): QueryClientQueryClient();
Remember to replace "YOUR_API_KEY"
with the API key from step 2.
Important: The chain you import (like arbitrumSepolia
) must come from
the @account-kit/infra
package, not from viem
. Additionally, make sure
this chain is enabled in both your Alchemy app and Account Kit config policy
in the dashboard.
Note: This is set up allows you to connect to other existing external EOAs such as MetaMask using our built-in connectors and WalletConnect. Learn more here
[
{
type: stringtype: "external_wallets",
walletConnect: {
projectId: string;
}walletConnect: { projectId: stringprojectId: "your-project-id" },
},
];
4. Set up the Alchemy Provider
Wrap your application with the Alchemy Provider to enable embedded wallet functionality.
Create providers.tsx
Update your layout.tsx
5. Add authentication to your app
Now you can use the Alchemy React components to add wallet authentication anywhere in your app.
Example page with login functionality
6. Test your integration
- Start your development server
- Navigate to your app in the browser
- Click the “Login” button
- Try authenticating with different methods (email, social login, etc.)
- Once authenticated, you should see the success message with the user’s information
Congratulations! You now have embedded smart wallets working in your React application.
What’s next?
Now that you have basic authentication working, you can explore additional features:
- Send user operations to perform transactions
- Customize your UI components for advanced styling
- Add gas sponsorship for gasless transactions
- Set up multi-factor authentication for enhanced security