To be able to do any signing actions with your wallet account, it must be available for use in your wallet app. Some wallets allow you to sign without the need for that wallet account to be the currently selected one in the wallet app, but others do not. You can preemptively check if the wallet account is available for signing by calling the assertWalletAccountSigningAvailability function, which will throw a WalletAccountNotSelectedError error in case the wallets app required the wallet account to be the currently selected one and the wallet account you trying to sign the message with is not the currently selected one. We’ll do the same check once a sign function is called, but you can check it beforehand to avoid errors.

Usage

import {
    assertWalletAccountSigningAvailability,
    type WalletProviderMethodUnavailableError
} from '@dynamic-labs-sdk/client';

const doSomeSignAction = async () => {
    try {
        await assertWalletAccountSigningAvailability({ walletAccount });
    } catch (error instanceof WalletAccountNotSelectedError) {
        console.error(error);
        // Prompt user to reconnect and/or make the required wallet account active in their wallet app
        return;
    }

    // Do some sign action
    // ...
}

Error Handling

If the wallet account you’re checking is not connected and active in the wallet app, the function will throw a WalletAccountNotSelectedError error. The error contains an expectedAddress, which is the address that you are trying to sign the message with, and a selectedAddress, which is the address that is currently active in the wallet app. If there is no selectedAddress prop, it probably means that there is no connected wallet accounts to your app.