Overview
Message signing allows users to prove ownership of their wallet by signing arbitrary messages. This is commonly used for authentication and verification.Prerequisites
- Dynamic SDK initialized (see Installation Guide)
- User authenticated (see Authentication Guide)
- EVM wallet available (see Wallet Creation)
dynamic_sdk_web3dartpackage installed
Sign a Message
Sign a raw (pre-hashed) message
UsesignRawMessage to sign an already-hashed 32-byte digest directly, without the EIP-191 prefix or any additional hashing. This gives you full control over the hashing and serialization, which is what secp256k1-derived chains (Cosmos, Tron, XRP) rely on. To EIP-191 personal-sign raw bytes instead, use signMessageBytes.
Unlike signMessage, signRawMessage is a WaaS (embedded wallet) operation, so it takes the wallet’s walletId and accountAddress rather than a BaseWallet. The message is the pre-hashed digest as a hex string without the 0x prefix.
Method signature
Sign context (SignMessageContext)
Signing a raw digest hides what the bytes actually represent, so some environments configure a signing policy that rejects context-less raw signs. For those, pass a typed SignMessageContext describing what the digest was derived from. The MPC relay policy engine cryptographically validates the context against the digest, so the payload must be the exact source of the digest — a mismatched context is rejected just like a missing one.
SignMessageContext is exported from package:dynamic_sdk/dynamic_sdk.dart and provides named factories for the common variants:
evmMessage factory with the 0x-prefixed hex of the bytes behind the digest:
SignMessageContextType and its payload:
SignMessageContextType covers btcTransaction, eip7702Auth, evmMessage, evmTransaction, evmTypedData, evmUserOperation, stellarMessage, suiMessage, suiTransaction, svmMessage, and svmTransaction.
The
context parameter is optional. Only environments whose signing policy requires it will reject a raw sign that omits it — otherwise you can call signRawMessage without a context.Sign raw bytes (EIP-191)
UsesignMessageBytes to personal-sign raw bytes with the EIP-191 prefix applied and the message hashed before signing (equivalent to viem’s signMessage({ raw })). Use this to personal-sign a 32-byte hash such as an ERC-4337 userOpHash, when you want the EIP-191 prefix — unlike signRawMessage, which signs the digest as-is.
Sign Message Widget
Common Use Cases
Authentication
Signing User Actions
Off-Chain Signatures
Verify Signatures
While signature verification typically happens on the backend or smart contract, here’s how to structure the verification data:Best Practices
1. Always Handle Errors
2. Include Context in Messages
3. Show Loading States
4. Clear Sensitive Data
Error Handling
Complete Authentication Flow
Next Steps
- Typed Data Signing - Sign structured data (EIP-712)
- Send ETH Transactions - Send transactions
- Smart Contract Interactions - Interact with contracts