Allow users to connect a wallet or authenticate with a wallet.

Prerequisites

Connect and verify a wallet in a single SDK call

import { connectAndVerifyWithWalletProvider } from '@dynamic-labs-sdk/client';

const signInWithWallet = async (key) => {
  try {
    const walletAccount = await connectAndVerifyWithWalletProvider({
      walletProviderKey: key,
    });

    console.log(`Wallet account connected and verified: ${walletAccount.accountAddress}`);

    // User is now signed in and available in the dynamicClient.user property
    // walletAccount is now available with getWalletAccounts()
    // ...
  } catch (error) {
    console.error('Error connecting or verifying wallet: ', error);

    // No Dynamic user was created, the user is not signed in
  }
};

Connect a wallet without verifying it

import { connectWithWalletProvider } from '@dynamic-labs-sdk/client';

const signInWithWallet = async (key) => {
  try {
    const walletAccount = await connectWithWalletProvider({
      walletProviderKey: key,
    });

    console.log(`Wallet account connected: ${walletAccount.accountAddress}`);

    // No Dynamic user was created, but the session has been established
    // walletAccount is now available with getWalletAccounts()
    // ...
  } catch (error) {
    console.error('Error connecting wallet: ', error);

    // Connection failed and session was not established
  }
};

Verify a connected wallet account

You can use this function to verify a wallet account that was connected but not verified before.
import { verifyWalletAccount } from '@dynamic-labs-sdk/client';

const verifyWallet = async (walletAccount) => {
  try {
    const walletAccount = await verifyWalletAccount({
      walletAccount
    });

    console.log(`Wallet is now verified: ${walletAccount.accountAddress}`);

    // A Dynamic user was created and is available in the dynamicClient.user property
    // walletAccount remains available in getWalletAccounts(), with a new `verifiedCredentialId` property
    // ...
  } catch (error) {
    console.error('Error verifying wallet: ', error);

    // No Dynamic user was created, but the existing session remains valid
  }
};