> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phantom.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign a message

> Ask users to sign a message with Phantom for authentication, ownership proofs, or agreement to terms.

Ask the user to sign a message. Useful for authentication, proving ownership, or agreeing to terms.

<Tabs>
  <Tab title="React">
    ```tsx theme={null}
    import { useSolana } from "@phantom/react-sdk";

    function SignMessage() {
      const { solana } = useSolana();

      const sign = async () => {
        const message = "Hello, please sign this message to verify your identity.";
        const { signature, publicKey } = await solana.signMessage(message);

        console.log("Signature:", signature);
        console.log("Public key:", publicKey);

        return signature;
      };

      return <button onClick={sign}>Sign Message</button>;
    }
    ```
  </Tab>

  <Tab title="Browser SDK">
    ```typescript theme={null}
    import { BrowserSDK, AddressType } from "@phantom/browser-sdk";

    const sdk = new BrowserSDK({
      providers: ["google", "apple", "injected"],
      appId: "your-app-id",
      addressTypes: [AddressType.solana],
    });

    const { signature, publicKey } = await sdk.solana.signMessage("Sign to verify");
    console.log("Signature:", signature);
    console.log("Public key:", publicKey);
    ```
  </Tab>

  <Tab title="React Native">
    ```tsx theme={null}
    import { useSolana } from "@phantom/react-native-sdk";
    import { View, Button, Alert, StyleSheet } from "react-native";

    function SignMessage() {
      const { solana } = useSolana();

      const sign = async () => {
        try {
          const message = "Hello, please sign this message to verify your identity.";
          const { signature, publicKey } = await solana.signMessage(message);

          Alert.alert("Signed!", `Public key: ${publicKey}`);
          return signature;
        } catch (error) {
          Alert.alert("Error", error instanceof Error ? error.message : "Signing failed");
          throw error;
        }
      };

      return (
        <View style={styles.container}>
          <Button title="Sign Message" onPress={sign} />
        </View>
      );
    }

    const styles = StyleSheet.create({
      container: {
        padding: 20,
        gap: 10,
      },
    });
    ```
  </Tab>
</Tabs>
