You can sign a message with a wallet account by calling the signMessage function. See Checking Wallet Account Availability for more information.

Usage

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

const handleSignMessage = async () => {
    try {
        // Replace with the message you want to sign
        const { signature } = await signMessage({ walletAccount, message: 'Hello, world!' });
        console.log(signature);
    } catch (error instanceof WalletAccountNotSelectedError) {
        console.error(error);
        // You might want to prompt user to reconnect or make the required wallet account active in their wallet app
    }
}

Error Handling

If the wallet account you trying to sign the message with 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.