Commands

Sign Message

Sign message lets you create an EIP-191 signature.

Using the command

Async handlersEvent listeners

Sending the command & handling the response

The response will include a signature compliant with EIP-191. You should verify the signature.

type MiniAppSignMessageSuccessPayload = {
  status: "success";
  signature: string;
  address: string;
  version: number;
};

app/page.tsx

import { MiniKit, SignMessageInput } from '@worldcoin/minikit-js'

const signAndVerifyMessage = async () => {
  const signMessagePayload: SignMessageInput = {
    message: "Hello world",
  };

  const {finalPayload} = await MiniKit.commandsAsync.signMessage(signMessagePayload);

  if (finalPayload.status === "success") {
    const messageHash = hashSafeMessage(messageToSign);

    const isValid = await (
      await Safe.init({
        provider:
          "https://opt-mainnet.g.alchemy.com/v2/your-api-key",
        safeAddress: finalPayload.address,
      })
    ).isValidSignature(messageHash, finalPayload.signature);

    // Checks functionally if the signature is correct
    if (isValid) {
      console.log("Signature is valid");
    }
  }
};

Your message is verified!