Skip to content

useSignMessage

Hook for signing messages with connected account.

import { useSignMessage } from 'wagmi'

Usage

The following examples use the message: gm wagmi frens.

import { useSignMessage } from 'wagmi'
const App = () => {
const [{ data, error, loading }, signMessage] = useSignMessage({
message: 'gm wagmi frens',
})
if (!data)
return (
<button disabled={loading} onClick={async () => await signMessage()}>
Sign message
</button>
)
return (
<div>
{data && <div>Signature: {data}</div>}
{error && <div>Error signing message</div>}
</div>
)
}

Return Values

result

{
data?: string
error?: Error
loading?: boolean
}

signMessage

(config?: {
message: string
}) => Promise<{ data?: string; error?: Error }>

Configuration

message (optional)

Message to sign with wallet.

import { useSignMessage } from 'wagmi'
const App = () => {
const [{ data, error, loading }, signMessage] = useSignMessage({
message: 'gm wagmi frens',
})
return ...
}