Skip to main content
The AbstractClient includes a signMessage method that can be used to sign a message using the connected Abstract Global Wallet. The method follows the EIP-1271 standard for contract signature verification.

View Example Repository

View an example implementation of signing and verifying messages with AGW in a Next.js app.

Usage

import { useAbstractClient } from "@abstract-foundation/agw-react";

export default function SignMessage() {
  const { data: agwClient } = useAbstractClient();

  async function signMessage() {
    if (!agwClient) return;

    // Alternatively, you can use Wagmi useSignMessage: https://wagmi.sh/react/api/hooks/useSignMessage
    const signature = await agwClient.signMessage({
      message: "Hello, Abstract!",
    });
  }
}
import { createPublicClient, http } from "viem";
import { abstractTestnet } from "viem/chains";

// Create a public client to verify the message
const publicClient = createPublicClient({
  chain: abstractTestnet,
  transport: http(),
});

// Verify the message
const isValid = await publicClient.verifyMessage({
  address: walletAddress, // The AGW address you expect to have signed the message
  message: "Hello, Abstract!",
  signature,
});

Parameters

message
string | Hex
required
The message to sign. Can be a string or a hex value.
account
Account
required
The account to sign the message with. Use the account from the AbstractClient to use the Abstract Global Wallet.

Returns

Returns a Promise<Hex> containing the signature of the message.

Verification

To verify a signature created by an Abstract Global Wallet, use the verifyMessage function from a public client: