Skip to main content

Sign Message

Sign arbitrary messages with a user’s embedded Solana wallet. Message signing is commonly used for authentication, proof of ownership, and off-chain authorization.

Overview

Solana message signing allows users to cryptographically sign messages using their wallet’s private key. This enables:
  • Proof of ownership: Verify control of a Solana address
  • Authentication: Sign messages to prove identity
  • Off-chain actions: Authorize actions without transaction fees
  • Session tokens: Create authenticated session credentials
Unlike Ethereum which uses personal_sign, Solana uses the signMessage method from the Solana Wallet Standard.

React SDK

To sign a message, use the signMessage method from the useSignMessage hook:

Parameters

Uint8Array
required
The message to sign as a Uint8Array. Use TextEncoder to convert strings to Uint8Array.Example:
Wallet
required
The Solana wallet to use for signing.Example:

Options Object

The second parameter is an optional configuration object:
object
Configuration for the signing confirmation modal.

Hook Callbacks

(result: { signature: Uint8Array; signedMessage: Uint8Array }) => void
Callback executed after successful signing. Receives the signature and signed message as Uint8Array.
(error: Error) => void
Callback executed if signing fails or user cancels.

Returns

Uint8Array
The signature produced by the wallet as a Uint8Array. Use bs58.encode() to convert to a base58 string.
Uint8Array
The original message that was signed.

Message Encoding

String to Uint8Array

Convert string messages to Uint8Array using TextEncoder:

Structured Messages

For structured authentication messages:

Signature Encoding

Convert to Base58

Solana signatures are typically represented as base58 strings:

Install bs58

Complete Examples

User Authentication

Session Authorization

Proof of Ownership

Verifying Signatures

Client-side Verification

Install Dependencies

UI Customization

Customize the signing modal:

Hide Modal

Hiding the modal removes the user’s ability to review the message before signing. Only use this for trusted operations or after obtaining explicit user consent.

Best Practices

Always provide clear context about what the user is signing:
Include a unique nonce in each message:
Include timestamps to make signatures time-limited:
Keep the original message to verify later:
Provide clear error messages:

Troubleshooting

Common causes:
  • Message mismatch: Ensure exact same message is used for verification
  • Encoding issues: Use consistent encoding (TextEncoder for strings)
  • Signature format: Ensure signature is properly base58 encoded/decoded
  • Public key format: Verify public key is valid Solana address
In Node.js environments, you may need to polyfill:
Ensure bs58 is properly installed:
Configure callbacks on hook initialization:

Sign Transaction

Sign Solana transactions

Send Transaction

Send transactions to the Solana network

Solana Web3.js

Official Solana JavaScript library

TweetNaCl

Cryptography library for verification

Next Steps