Message signing is commonly used for authentication, proving wallet ownership, or authorizing actions without sending a blockchain transaction.
How it works
When your application requests a message signature:- Your app calls the sign message method from the MoonKey SDK
- The Sign Message screen appears, displaying the message content
- User reviews the message details
- User approves or rejects the signature request
- If approved, the signed message is returned to your application
Triggering the Sign Message screen
Use theuseSignMessage hook from the MoonKey SDK to trigger the Sign Message screen:
- Ethereum
- Solana
Customizing the Sign Message screen
You can customize the Sign Message screen by passing UI options in theoptions.uiOptions object when calling signMessage:
Configuration options
Basic UI Options
string
Custom title text displayed at the top of the Sign Message screen.Example:
string
Custom description text displayed below the title, providing context for the signature request.Example:
string
Custom text for the confirmation button.Default:
'Sign'Example:boolean
Whether to show wallet information (address, balance) in the Sign Message screen.Default:
trueExample:Solana-specific Options
TransactionCommitment
The commitment level to use for Solana transactions.Available values:
'processed', 'confirmed', 'finalized'Example:TransactionEncoding
The encoding format for the Solana transaction.Available values:
'base58', 'base64'Example:Common use cases
Authentication verification
Prove wallet ownership for authentication:Third-party service login
Sign in to external services with wallet signature:Action authorization
Authorize specific actions without gas fees:Terms and conditions acceptance
Cryptographically sign terms acceptance:Complete example
Here’s a complete example with custom UI configuration:User experience flow
1
Trigger signature request
Your application calls
signMessage() with a message, wallet, and optional UI options.2
Sign Message screen appears
The customized Sign Message screen is displayed to the user.
3
Review message
User reviews the message content, title, and description.
4
Approve or reject
User clicks the confirm button to sign, or cancels/closes the modal to reject.
5
Signature created
If approved, MoonKey signs the message with the user’s wallet private key.
6
Return to application
The signature is returned to your application as an object containing the signature string (Ethereum) or Uint8Array (Solana).
Message signing vs. transaction signing
It’s important to understand the difference:Message Signing (this screen)
Message Signing (this screen)
- Signs arbitrary text or data
- Does not cost gas fees
- Does not modify blockchain state
- Used for authentication, verification, or authorization
- Instant and free
- Example: “Sign this message to log in”
Transaction Signing
Transaction Signing
- Signs blockchain transactions
- Costs gas fees (requires native currency)
- Modifies blockchain state (transfers tokens, calls contracts, etc.)
- Used for actual blockchain operations
- Requires network confirmation
- Example: “Sign this transaction to send 1 ETH”
Best practices
Provide clear context
Provide clear context
Always include a clear
description explaining why the user needs to sign:Include timestamps or nonces
Include timestamps or nonces
Prevent replay attacks by including unique data:
Handle rejections gracefully
Handle rejections gracefully
Users may decline to sign. Always handle errors:
Show wallet details when relevant
Show wallet details when relevant
Use Set to
showWalletUI: true when wallet context is important:false for a cleaner UI when wallet details aren’t relevant.Keep messages concise
Keep messages concise
Users are more likely to read and understand shorter messages:
- Use clear, simple language
- Break long messages into lines with
\n - Highlight important information
Check for wallet before signing
Check for wallet before signing
Always verify the user has a wallet before attempting to sign:
Global appearance settings
The Sign Message screen also respects global appearance settings fromMoonKeyProvider:
Security considerations
For developers:- Verify signatures server-side - Always validate signatures on your backend before trusting them
- Use nonces - Include unique identifiers to prevent replay attacks
- Include context - Clearly state what the signature authorizes
- Set expiration - Include timestamps and reject old signatures
- Validate message format - Ensure the signed message matches your expected format
- Displaying the full message content
- Showing their wallet address
- Providing clear context via title and description
- Allowing them to reject the request
Verifying signatures
After obtaining a signature, you typically want to verify it on your backend:- Ethereum
- Solana
Next steps
Sign Transaction
Sign blockchain transactions
Send Transaction
Send transactions with UI
UI Components Overview
Explore all UI components
Configure Appearance
Global appearance settings