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.
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';
const unsubscribe = onWalletProviderEvent({
callback: ({ addresses }) => {
console.log('Accounts changed event was called with', addresses);
},
event: 'accountsChanged',
walletProviderKey: 'metamaskevm',
});
// Call unsubscribe() when you no longer need the listener
Return the unsubscribe function from useEffect so the listener is cleaned up when the component unmounts:import { onWalletProviderEvent } from '@dynamic-labs-sdk/client';
import { useEffect } from 'react';
function useWalletProviderEvent(walletProviderKey: string) {
useEffect(() => {
return onWalletProviderEvent({
walletProviderKey,
event: 'accountsChanged',
callback: ({ addresses }) => {
console.log('Accounts changed:', addresses);
},
});
}, [walletProviderKey]);
}
Available events
accountsChanged: (params: { addresses: string[] }) => void;
disconnected: () => void;
networkChanged: (params: { networkId: string }) => void;