Introduction

It’s not neccessary for a wallet to be associated with a user when they sign up, but the likelyhood is that if a user is interacting with Web3, one will be connected at some point, whether embedded or external (branded).

Primary Wallet

Normally, if one or more wallets are connected, a primaryWallet object will be available on the Dynanmic Context which you can access with the useDynamicContext hook. This is a quick and easy way to access the main wallet associated with that user.

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.

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}: {wallet.isPrimary ? 'Primary' : 'Secondary'}
        </p>
      ))}
    </div>
  )
}

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.

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

So what does a wallet actually look like? Here’s the object:

Wallet Interface

FieldDescription
address: stringPublic key/address of the connected wallet
chain: stringCurrent BlockChain name
connected: booleanWhether this wallet is connected or not i.e. if locked in the browser extension
connector: WalletConnectorSee WalletConnector guide
network?: stringnumberThe network id of the chain the wallet is connected to
authenticated: booleanIf there is a current user, this will be true if and only if the user has signed this wallet to link it to their account
additionalAddresses?: string[]Additional addresses associated to the wallet like ordinals and payment addresses for bitcoin wallets

Here’s an example of a wallet object:

{
  address: '0x1234567890abcdef',
  chain: 'EVM',
  connected: true,
  connector: WalletConnector,
  network: '1',
  authenticated: true,
  additionalAddresses: []
}

What next?

What next?

Click here to learn how to interact with wallets.