You’re viewing the 2.0 (LTS) docs. View the current 3.0 version of this page.
useSignMessage hook provides functionality to sign arbitrary messages with the user’s wallet.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Hook for signing messages with a wallet
useSignMessage hook provides functionality to sign arbitrary messages with the user’s wallet.
import { useSignMessage } from "@getpara/react-sdk";
function MessageSigner() {
const { signMessage, signMessageAsync, isPending, error } = useSignMessage();
const [message, setMessage] = useState("");
const [signature, setSignature] = useState("");
const handleSign = async () => {
try {
const result = await signMessageAsync({
messageBase64: Buffer.from(message).toString("base64"),
});
if ("signature" in result) {
setSignature(result.signature);
}
} catch (err) {
console.error("Failed to sign message:", err);
}
};
return (
<div>
<input
value={message}
onChange={(e) => setMessage(e.target.value)}
placeholder="Enter message to sign"
/>
<button
onClick={handleSign}
disabled={isPending || !message}
>
{isPending ? "Signing..." : "Sign Message"}
</button>
{signature && <p>Signature: {signature}</p>}
</div>
);
}