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
- Basic Usage
- With Callbacks
- With UI Customization
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 usingTextEncoder:
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
Best Practices
Include context in messages
Include context in messages
Always provide clear context about what the user is signing:
Use nonces to prevent replay attacks
Use nonces to prevent replay attacks
Include a unique nonce in each message:
Add timestamps for expiration
Add timestamps for expiration
Include timestamps to make signatures time-limited:
Store message with signature
Store message with signature
Keep the original message to verify later:
Handle errors gracefully
Handle errors gracefully
Provide clear error messages:
Troubleshooting
Signature verification fails
Signature verification fails
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
TextEncoder not defined
TextEncoder not defined
In Node.js environments, you may need to polyfill:
bs58 import errors
bs58 import errors
Ensure bs58 is properly installed:
Callback not firing
Callback not firing
Configure callbacks on hook initialization:
Related Documentation
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
- Learn about Solana transaction signing
- Understand Solana’s signature verification
- Explore Sign-In With Solana (SIWS) standard
- Implement session-based authentication with signed messages