> ## 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.

# Signing a Message

You can sign a message with a wallet account by calling the `signMessage` function.

See [Checking Wallet Account Availability](/javascript/reference/wallets/check-wallet-account-availability) for more information.

## Usage

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={"system"}
    import { signMessage } from '@dynamic-labs-sdk/client';

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

  <Tab title="React">
    ```tsx theme={"system"}
    import { type WalletAccount } from '@dynamic-labs-sdk/client';
    import { useSignMessage } from '@dynamic-labs-sdk/react-hooks';

    const MESSAGE = 'Hello, world!';

    function SignMessageButton({ walletAccount }: { walletAccount: WalletAccount }) {
      const { mutate: signMessage, data, isPending, error } = useSignMessage();

      return (
        <div>
          <button
            onClick={() => signMessage({ walletAccount, message: MESSAGE })}
            disabled={isPending}
          >
            {isPending ? 'Signing…' : 'Sign message'}
          </button>
          {data?.signature && <p>Signature: {data.signature}</p>}
          {error && <p>Error: {error.message}</p>}
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

## 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.

## Related functions

* [Checking Wallet Account Availability](/javascript/reference/wallets/check-wallet-account-availability)
* [Getting the Wallet Account Given an Address and Chain](/javascript/reference/wallets/get-wallet-account-from-address)
* [Wallet Provider Events](/javascript/reference/wallets/wallet-provider-events)
