You can listen to events emitted by the wallet provider by using the onWalletProviderEvent. It will return an unsubscribe function that you can call to stop listening to the event.

Usage

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

// Replace with the wallet provider key you want to listen to, the event you want to listen to
// and the appropriate callback function
const unsubscribe = onWalletProviderEvent({
    callback: ({ addresses }) => {
     console.log('Accounts changed event was called with', addresses);
    },
    event: 'accountsChanged',
    walletProviderKey: 'metamaskevm',
});

const cleanup = () => {
  unsubscribe();
};

Available events

  • accountsChanged: (params: { addresses: string[] }) => void;
  • disconnected: () => void;
  • networkChanged: (params: { networkId: string }) => void;