> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Accessing Connected Wallets

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

### Primary Wallet

Normally, if one or more wallets are connected, a `primaryWallet` object will be available on the Dynamic Context which you can access with [the `useDynamicContext` hook](/react/reference/hooks/usedynamiccontext). This is a quick and easy way to access the main wallet associated with that user.

```tsx React theme={"system"}
const { primaryWallet } = useDynamicContext();
```

### useUserWallets

Going beyond the primary wallet, you might want to get every wallet associated with the given user. The best option for this is to use [the `useUserWallets` hook](/react/reference/hooks/wallets/useuserwallets).

```tsx React theme={"system"}
import { FC } from 'react'
import { useUserWallets } from '@dynamic-labs/sdk-react-core'

export const ListConnectedWallets: FC = () => {
  const userWallets = useUserWallets()

  return (
    <div>
      <h1>Wallets</h1>

      {userWallets.map((wallet) => (
        <p key={wallet.id}>
          {wallet.address}
        </p>
      ))}
    </div>
  )
}
```

### Check Which Wallet is Embedded

You can check which wallet is embedded by using the `useUserWallets` hook and looking for the `isEmbeddedWallet` boolean.

```tsx React theme={"system"}
import { useUserWallets } from '@dynamic-labs/sdk-react-core';

const userWallets = useUserWallets();

const embeddedWallet = userWallets.find(wallet => wallet.connector.isEmbeddedWallet);
```

### onEmbeddedWalletCreated

If you're using embedded wallets, you can listen for the `onEmbeddedWalletCreated` event to know when a wallet has been created for a user. This is useful for when you want to know when a user has a wallet created for them, but you don't want to have to poll the API to check.

```tsx React theme={"system"}
<DynamicContextProvider
  settings={{
    events: {
      onEmbeddedWalletCreated: (args) => {
        console.log('onEmbeddedWalletCreated was called', args);
      }
    }
  }}
>
{/* ... rest of your app ... */}
</DynamicContextProvider>
```

## Add extra logic during any wallet connection (handleConnectedWallet)

Sometimes you may want to inject some of your own logic during the process of a wallet becoming connected. Dynamic has a concept of ["handlers"](/react/reference/handlers/handlers-introduction), which is a particular kind of callback to allow custom code to run as part of a process (i.e. signup).

`handleConnectedWallet` is a handler that runs before we establish the wallet connection. You can use this callback to run your logic and reject (by returning boolean false). For example, running a fraud check before establishing the connection.

<Tip>The args returned by handleConnectedWallet is a [Wallet](/react/wallets/using-wallets/accessing-wallets#wallet-interface) but without the `connected` boolean.</Tip>

```tsx React theme={"system"}
<DynamicContextProvider
  settings={{
    handlers: {
      handleConnectedWallet: (args) => {
        console.log("handleConnectedWallet was called", args);
        // if runYourOwnLogic return true, the connection will be established, otherwise it will not
        return runYourOwnLogic();
      },
    },
  }}
>
  {/* ... rest of your app ... */}
</DynamicContextProvider>
```

<Info>
  Using the JavaScript SDK? See [Getting Wallet Accounts](/javascript/reference/wallets/get-wallet-accounts) and [Remove Wallet Account](/javascript/reference/wallets/remove-wallet-account) for the equivalent guides.
</Info>

## What next?

<Card title="What next?" href="/react/wallets/using-wallets/evm/using-evm-wallets" icon="link" color="#4779FE">
  Continue with chain-specific guides (for example EVM).
</Card>
