Skip to main content
When using Privy’s server-side SDKs to sign messages, you can use the authorization context to automatically sign requests. Learn more about signing on the server.
Use the signMessage method exported from the useSignMessage hook to sign a message with a Solana wallet.
signMessage: ({
  message,
  options
}: {
  message: Uint8Array;
  wallet: ConnectedStandardSolanaWallet;
  options?: {
    uiOptions?: SignMessageModalUIOptions;
  };
}) =>
  Promise<{
    signature: Uint8Array;
  }>;

Usage

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

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

const selectedWallet = wallets[0];

const message = 'Hello world';
const signatureUint8Array = (
  await signMessage({
    message: new TextEncoder().encode(message),
    wallet: selectedWallet,
    options: {
      uiOptions: {
        title: 'Sign this message'
      }
    }
  })
).signature;
const signature = bs58.encode(signatureUint8Array);

Parameters

message
Uint8Array
required
Message to be signed as a Uint8Array.
wallet
string
The Solana wallet to use for signing the message.
options
{uiOptions?: SignMessageModalUIOptions}
Additional options for signing the message.

Response

signature
Uint8Array
The signature produced by the wallet.
signedMessage
Uint8Array
The original message that was signed.