Skip to content

This guide will walk you through the process of integrating the Wallet SDK into your React application. By the end, you’ll have a basic setup that allows users to connect their Frak Wallet and perform simple interactions.

Before you begin, ensure that:

  1. You have a React project set up.
  2. You have a merchant account on the Frak business dashboard with your storefront’s domain registered. The main domain is registered automatically at sign-up; for subdomains, add them under Allowed Domains on the dashboard.

If you haven’t completed these steps, please refer to the Getting Started guide.

First, install the required packages:

Terminal window
npm install @frak-labs/react-sdk @tanstack/react-query

Create a new component to set up the Frak client and iframe:

FrakProvider.tsx
import {
import FrakConfigProvider
FrakConfigProvider
,
import FrakIFrameClientProvider
FrakIFrameClientProvider
,
} from "@frak-labs/react-sdk";
import {
class QueryClient
QueryClient
,
const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => React.JSX.Element
QueryClientProvider
} from "@tanstack/react-query";
import type {
type PropsWithChildren<P = unknown> = P & {
children?: React.ReactNode | undefined;
}
PropsWithChildren
} from "react";
const
const queryClient: QueryClient
queryClient
= new
new QueryClient(config?: QueryClientConfig): QueryClient
QueryClient
();
const
const frakConfig: {
metadata: {
name: string;
};
}
frakConfig
= {
metadata: {
name: string;
}
metadata
: {
name: string
name
: "Your App Name",
},
// The domain will be automatically set to window.location.host
};
export function
function FrakProvider({ children }: PropsWithChildren): React.JSX.Element
FrakProvider
({
children: React.ReactNode
children
}:
type PropsWithChildren<P = unknown> = P & {
children?: React.ReactNode | undefined;
}
PropsWithChildren
) {
return (
<
const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => React.JSX.Element
QueryClientProvider
client: QueryClient
client
={
const queryClient: QueryClient
queryClient
}>
<
import FrakConfigProvider
FrakConfigProvider
config: {
metadata: {
name: string;
};
}
config
={
const frakConfig: {
metadata: {
name: string;
};
}
frakConfig
}>
<
import FrakIFrameClientProvider
FrakIFrameClientProvider
>{
children: React.ReactNode
children
}</
import FrakIFrameClientProvider
FrakIFrameClientProvider
>
</
import FrakConfigProvider
FrakConfigProvider
>
</
const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => React.JSX.Element
QueryClientProvider
>
);
}

Wrap your main App component with this provider:

App.tsx
import {
import FrakProvider
FrakProvider
} from './FrakProvider';
function
function App(): any
App
() {
return (
<
import FrakProvider
FrakProvider
>
{/* Your app content */}
</
import FrakProvider
FrakProvider
>
);
}
export default
function App(): any
App
;

For more detailed configuration options, see FrakWalletSdkConfig.

Create a component to check and display the wallet status using the useWalletStatus hook:

WalletStatus.tsx
/**
* Simple wallet status component
*/
function
function WalletStatus(): any

Simple wallet status component

WalletStatus
() {
const {
any
data
:
const walletStatus: any
walletStatus
,
const isLoading: any
isLoading
,
const error: any
error
} =
any
useWalletStatus
();
if (
const isLoading: any
isLoading
) return <
any
div
>Loading wallet status...</
any
div
>;
if (
const error: any
error
) return <
any
div
>Error: {
const error: any
error
.
any
message
}</
any
div
>;
return (
<
any
div
>
Wallet status:{" "}
{
const walletStatus: any
walletStatus
?.
any
key
=== "connected" ? "Connected" : "Not connected"}
</
any
div
>
);
}

Create a component for the login modal, using the useDisplayModal hook:

LoginButton.tsx
/**
* Simple login with frak button
*/
function
function LoginButton(): any

Simple login with frak button

LoginButton
() {
const {
any
mutate
:
const displayModal: any
displayModal
,
const isPending: any
isPending
} =
any
useDisplayModal
();
const
const handleLogin: () => void
handleLogin
= () => {
const displayModal: any
displayModal
({
steps: {
login: {};
}
steps
: {
login: {}
login
: {},
},
metadata: {
i18n: {
"sdk.modal.login.description": string;
};
}
metadata
: {
i18n: {
"sdk.modal.login.description": string;
}
i18n
: {
"sdk.modal.login.description":
"Login with Frak to receive up to {{ estimatedReward }}!",
},
},
});
};
return (
<
any
button
onClick: () => void
onClick
={
const handleLogin: () => void
handleLogin
}
disabled: any
disabled
={
const isPending: any
isPending
}
type: string
type
={"button"}>
{
const isPending: any
isPending
? "Logging in..." : "Login with Frak"}
</
any
button
>
);
}

Update your main App component to include the wallet status and login button:

function
function App(): any
App
() {
return (
<
any
FrakProvider
>
<
any
h1
>My Frak Powered app</
any
h1
>
<
any
WalletStatus
/>
<
any
LoginButton
/>
</
any
FrakProvider
>
);
}
export default
function App(): any
App
;

With this setup, you have a basic React application integrated with the Wallet SDK. Users can now connect their Frak Wallet and log in. From here, you can start implementing more advanced features such as:

  • Sending interactions
  • Implementing referral systems
  • Creating reward campaigns

Refer to the specific action and hook documentation for details on implementing these features.