Function to sign messages using the connected Abstract Global Wallet.
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.
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 messageconst publicClient = createPublicClient({ chain: abstractTestnet, transport: http(),});// Verify the messageconst isValid = await publicClient.verifyMessage({ address: walletAddress, // The AGW address you expect to have signed the message message: "Hello, Abstract!", signature,});