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

# Sign a message

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

In this example, we are going to sign a message for Bitcoin.

```tsx theme={"system"}
      import { isBitcoinWallet } from '@dynamic-labs/bitcoin';

      // the wallet object is the wallet you want to send from
      // you can access the available wallets via the `useUserWallets` hook
      // or get the primaryWallet via the `useDynamicContext` hook
      const SignMessageButton = ({ wallet }) => {
        const onSignMessage = async () => {
          if (!isBitcoinWallet(wallet)) {
            return;
          }

          const signature = await wallet.signMessage('example');

          console.log('signature', signature);
        };

        return <button onClick={onSignMessage}>Sign message</button>;
      };
```

You can also sign a message with a specific address type (payment or ordinal) or protocol (ecdsa or bip322-simple), as shown below:

```tsx theme={"system"}
      import { isBitcoinWallet } from '@dynamic-labs/bitcoin';

      const SignMessageButton = ({ wallet }) => {
        const onSignMessage = async () => {
          if (!isBitcoinWallet(wallet)) {
            return;
          }

          // The `addressType` can be 'payment' or 'ordinals'
          // The `protocol` can be 'ecdsa' or 'bip322-simple'
          const signature = await wallet.signMessage('example', { addressType: 'ADDRESS_TYPE', protocol: 'PROTOCOL' });

          console.log('signature', signature);
        };

        return <button onClick={onSignMessage}>Sign message</button>;
      };
```

Notes:

* Some wallets don't allow you to specify the address type or protocol. In this case, we'll just default to the address type and protocol that the wallet supports.
* If you don't specify an address type, we'll default to the address type that the wallet supports or ordinals address.
* If you don't specify a protocol, we'll use the default protocol for the wallet.
