Hooks
useSignMessage

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

PropertyTypeDescription
signMessage(message: Uint8Array) => voidSign the given message bytes
isPendingbooleanTrue while the wallet is signing
isSuccessbooleanTrue after signing succeeds
isErrorbooleanTrue if signing failed or was rejected
errorError | nullThe error, if any
dataUint8Array | undefinedThe signature bytes on success
reset() => voidReset 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.verify from the tweetnacl package with the signer's public key.