Skip to content

Integrate Web3-React App

With Web3-React wallet connector framework, developers can allow app users to easily switch between multiple wallets within a single application. The Arcana Auth SDK offers a custom Web3-React connector that enables the Arcana wallet in apps using Web3-React.

In this guide, you will learn how to integrate the Arcana Auth SDK with apps that use Web3-React wallet connectors.

Prerequisites

  • Register Web3 Application: Log into the Arcana Developer Dashboard https://dashboard.arcana.network to register and configure the app before they can use the Arcana Auth SDK and enable the Arcana wallet for authenticated app users.

  • Set up Authentication Providers: Click on the Social Auth tab in the Arcana Developer Dashboard. Configure and select one or more supported authentication providers for onboarding the app users.

    Configure Authentication Providers

    You may be required to configure additional provider details for different authentication providers. In the case of Google, the developer must use Google Developer Console to set up the app and generate a Google assigned client ID for Google OAuth. This Google ClientID will be configured in the Arcana Developer Dashboard Social Auth settings before integrating the app.

    For details, see how to configure authentication providers.

  • Save the Client ID assigned to the app and displayed in the Arcana Developer Dashboard. It is required later during integrating with the Arcana Auth SDK.

Steps

Integrating Web3-React apps with the Arcana Auth SDK is simple!

Follow these three steps:

Step 1: Install Arcana Auth SDK packages

npm install --save @arcana/auth-web3-react @arcana/auth
yarn add @arcana/auth-web3-react @arcana/auth
<script src="https://cdn.jsdelivr.net/npm/@arcana/auth"></script>
<script src="https://unpkg.com/@arcana/auth"></script>
<script src="https://cdn.jsdelivr.net/npm/@arcana/auth-web3-react"></script>
<script src="https://unpkg.com/@arcana/auth-web3-react"></script>

Step 2: Create AuthProvider and ArcanaConnector

Import auth package and create AuthProvider. Then import auth-wagmi package and create an ArcanaConnector.

Use the unique Client ID value assigned to the app afterregistration to instantiate the AuthProvider. Call initializeConnector from the web3-react/core library and instantiate the ArcanaConnector by specifying the AuthProvider as shown in the sample code below.

example/connectors/arcanaWallet.ts
import { initializeConnector } from "@web3-react/core";
import { ArcanaConnector } from "@arcana/auth-web3-react";
import { AuthProvider } from "@arcana/auth";
import { URLS } from "../chains";

const auth = new AuthProvider(
  "xar_test_b2ddexxxxxxxxxxxxxxxxxxxx8b1fa3f"
);
export const [arcanaConnect, hooks] = initializeConnector<ArcanaConnector>(
  (actions) =>
    new ArcanaConnector(auth, {
      actions,
    })
);
...

Step 3: Use ArcanaConnector

In the Web3-React app, use the ArcanaConnector and set up the required hooks:

example/components/connectorCards/ArcanaConnectCard.tsx
import { useEffect, useState } from "react";

import { MAINNET_CHAINS } from "../../chains";
import { hooks, arcanaConnect } from "../../connectors/arcanaWallet";
import { Card } from "../Card";

const CHAIN_IDS = Object.keys(MAINNET_CHAINS).map(Number);

const {
  useChainId,
  useAccounts,
  useIsActivating,
  useIsActive,
  useProvider,
  useENSNames,
} = hooks;

export default function ArcanaConnectCard() {
  const chainId = useChainId();
  const accounts = useAccounts();
  const isActivating = useIsActivating();

  const isActive = useIsActive();

  const provider = useProvider();
  const ENSNames = useENSNames(provider);

  const [error, setError] = useState(undefined);

  // attempt to connect eagerly on mount
  useEffect(() => {
    arcanaConnect.connectEagerly().catch((error) => {
      console.debug("Failed to connect eagerly to arcanaConnect", error);
    });
  }, []);

  return (
    <Card
      connector={arcanaConnect}
      activeChainId={chainId}
      chainIds={CHAIN_IDS}
      isActivating={isActivating}
      isActive={isActive}
      error={error}
      setError={setError}
      accounts={accounts}
      provider={provider}
      ENSNames={ENSNames}
    />
  );
}

Now, you are all set to onboard users in the Web3-React app using the plug-and-play login UI and enable Arcana wallet for the authenticated users.

pages/index.tsx
import ArcanaConnectCard from "../components/connectorCards/ArcanaConnectCard";
import CoinbaseWalletCard from "../components/connectorCards/CoinbaseWalletCard";
import GnosisSafeCard from "../components/connectorCards/GnosisSafeCard";
import MetaMaskCard from "../components/connectorCards/MetaMaskCard";
import NetworkCard from "../components/connectorCards/NetworkCard";
import WalletConnectCard from "../components/connectorCards/WalletConnectCard";
import WalletConnectV2Card from "../components/connectorCards/WalletConnectV2Card";
import ProviderExample from "../components/ProviderExample";

export default function Home() {
  return (
      <>
      <ProviderExample />
      <div>
        <MetaMaskCard />
        <WalletConnectV2Card />
        <WalletConnectCard />
        <CoinbaseWalletCard />
        <NetworkCard />
        <GnosisSafeCard />
        <ArcanaConnectCard />
      </div>
      );
      </>
}

That is all!

The Web3-React app is successfully integrated with the Arcana Auth SDK. Refer to the Auth Examples for working integration examples.

What's Next?

After integrating with a Web3-React app with the Arcana Auth SDK, the developers can add code to onboard users. The example above shows the built-in plug-and-play login UI method. There are two ways to onboard users:

  • Use built-in plug-and-play login UI with a single function call that displays all the configured authentication providers
  • Use custom login UI to onboard users and wire it to the Arcana Auth SDK passwordless onboarding functions loginWithLink(deprecated), loginWithOTPStart, loginWithOTPComplete or the social onboarding function loginWithSocial for calling the configured authentication providers.

Arcana wallet can also be used in applications that integrate with other wallet connectors such as Wagmi and Rainbow Kit. See how to enable Arcana wallet for apps using Wagmi and Rainbow Kit.

See also


Last update: April 11, 2024 by DocX, shaloo, shaloo