Setup authentication to smart wallets on React Native

In this step you will get your authentication working so users can login with their smart wallets.

Setup your application

First, configure your application and your API Key:

  1. Create an app in the dashboard and copy the API Key.

  2. Create a configuration in the Smart Wallets dashboard to enable login methods.

Hold onto your API Key for the next step.

Setup the Alchemy Accounts Provider

Now set up and configure the Alchemy Accounts Provider in your project.

You can do this by wrapping the top level component (e.g. _layout.tsx in Expo or App.tsx in Bare React Native) in your app with the AlchemyAccountsProvider component from the @account-kit/react-native package.

Here’s an example of how to do this:

1import "react-native-get-random-values"; // Shims for the crypto module
2import React from "react";
3import { alchemy, sepolia } from "@account-kit/infra";
4import {
5 AlchemyAccountProvider,
6 createConfig,
7} from "@account-kit/react-native";
8import { QueryClient } from "@tanstack/react-query";
9
10const queryClient = new QueryClient();
11
12const config = createConfig({
13 chain: sepolia,
14 transport: alchemy({
15 apiKey: "YOUR_ALCHEMY_API_KEY",
16 }),
17 signerConnection: {
18 apiKey: "YOUR_ALCHEMY_API_KEY",
19 },
20 sessionConfig: {
21 expirationTimeMs: 1000 * 60 * 60 * 24, // <-- Adjust the session expiration time as needed (currently 24 hours)
22 },
23});
24
25export default function App() {
26 return (
27 <AlchemyAccountProvider config={config} queryClient={queryClient}>
28 {/* The rest of your app here... */}
29 </AlchemyAccountProvider>
30 );
31}

Choose your authentication

Now that you have set up the Alchemy Accounts Provider, you can setup your authentication!

You can choose from many authentication guides with react native instructions, like this one on Email One-Time Passwords.

Next Steps

Once you have authentication working, you can explore additional features: