Skip to content
Sign Message

Sign Message

Signing messages is a great way to securely prove control of a specific address. The example below builds on the Connect Wallet Example and uses the useSignMessage hook. Try it out before moving on.

Step 1: Connect Wallet

Follow the Connect Wallet guide to get this set up.

Step 2: Add SignMessage Component

Add the useSignMessage hook and set up a basic form:

import * as React from 'react'
import { useSignMessage } from 'wagmi'
import { verifyMessage } from 'ethers/lib/utils'

export function SignMessage() {
  const recoveredAddress = React.useRef<string>()
  const { data, error, isLoading, signMessage } = useSignMessage({
    onSuccess(data, variables) {
      // Verify signature when sign message succeeds
      const address = verifyMessage(variables.message, data)
      recoveredAddress.current = address

  return (
      onSubmit={(event) => {
        const formData = new FormData(
        const message = formData.get('message')
        signMessage({ message })
      <label htmlFor="message">Enter a message to sign</label>
        placeholder="The quick brown fox…"
      <button disabled={isLoading}>
        {isLoading ? 'Check Wallet' : 'Sign Message'}

      {data && (
          <div>Recovered Address: {recoveredAddress.current}</div>
          <div>Signature: {data}</div>

      {error && <div>{error.message}</div>}

Step 3: Add To App

Import the SignMessage component and display it when the account is connected.

import { useAccount, useConnect, useDisconnect } from 'wagmi'

import { SignMessage } from './SignMessage'

export function Profile() {
  const { isConnected } = useAccount()
  const { connect, connectors, error, isLoading, pendingConnector } =
  const { disconnect } = useDisconnect()

  if (isConnected) {
    return (
        {/* Account content goes here */}
        <SignMessage />

  return <div>{/* Connect wallet content goes here */}</div>

Wrap Up

That's it! You now have a way for users to sign messages and securely prove control over a wallet address.