useSignMessage
Sign an arbitrary message with the connected wallet.
Import
import { useSignMessage } from '@wankmi/wankmi'Usage
import { useSignMessage } from '@wankmi/wankmi'
function SignMessage() {
const { signMessage, isPending, data: signature } = useSignMessage()
function handleSign() {
const message = new TextEncoder().encode('Hello from wankmi!')
signMessage(message)
}
return (
<div>
<button onClick={handleSign} disabled={isPending}>
{isPending ? 'Signing...' : 'Sign Message'}
</button>
{signature && (
<p>Signature: {Buffer.from(signature).toString('hex')}</p>
)}
</div>
)
}Return Value
| Property | Type | Description |
|---|---|---|
signMessage | (message: Uint8Array) => void | Sign the given message bytes |
isPending | boolean | True while the wallet is signing |
isSuccess | boolean | True after signing succeeds |
isError | boolean | True if signing failed or was rejected |
error | Error | null | The error, if any |
data | Uint8Array | undefined | The signature bytes on success |
reset | () => void | Reset the mutation state |
💡
The message must be encoded as Uint8Array. Use new TextEncoder().encode(yourString) to convert a plain string.
Notes
- The wallet adapter must support
signMessage. Phantom, Backpack, and Solflare all support this. - Message signing does not submit a transaction to the network — it only produces a signature that can be verified off-chain (e.g. for authentication).
- To verify the signature, use
nacl.sign.detached.verifyfrom thetweetnaclpackage with the signer's public key.