Use the signMessage method exported from the useSignMessage hook to sign a message with a Solana wallet.
signMessage: ({
  message,
  options
}: {
  message: Uint8Array;
  options?: {
    address?: string;
    uiOptions?: SignMessageModalUIOptions;
  };
}) => Promise<Uint8Array>;

Usage

import {useSolanaWallets, useSignMessage} from '@privy-io/react-auth/solana';
import bs58 from 'bs58';

const {wallets} = useSolanaWallets();
const {signMessage} = useSignMessage();

const message = 'Hello world';
const signatureUint8Array = await signMessage({
  message: new TextEncoder().encode(message),
  options: {
    address: wallets[0].address, // Optional: Specify the wallet to use for signing. If not provided, the first wallet will be used.
    uiOptions: {
      title: 'Sign this message'
    }
  }
});
const signature = bs58.encode(signatureUint8Array);

Parameters

message
Uint8Array
required
Message to be signed as a Uint8Array.
options.address
string
Address of the wallet to use for signing the message. Recommended when working with external wallets to ensure reliable functionality. If not provided, the first wallet will be used.

Response

signature
Uint8Array
The signature produced by the wallet.