Skip to content

useSignMessage

Signs a message with the given address and message. Supports ECDSA and BIP322 protocols.

If address is not provided, the default account address will be used. If protocol is not provided, BIP322 will be used by default.

Import

ts
import { useSignMessage } from "@midl/react";

Example

tsx
function SignMessage() {
  const { signMessage, isLoading, error, data } = useSignMessage();

  if (isLoading) return <p>Loading...</p>;
  if (error) return <p>Error: {error.message}</p>;

  return (
    <div>
      <p>{data?.signature}</p>
      <button
        onClick={() =>
          signMessage({ message: "Hello, world!" })
        }
      >
        Sign Message
      </button>
    </div>
  );
}

Parameters

NameTypeDescription
mutationUseMutationOptions(optional) Mutation options for react-query.
configConfig(optional) Custom config to override the default from context.

SignMessageVariables

NameTypeDescription
messagestringThe message to sign.
addressstring(optional) The address to sign with. If not provided, uses default account.
protocolstring(optional) The protocol to use (ECDSA or BIP322). Defaults to BIP322.

Returns

NameTypeDescription
signMessage(variables: SignMessageVariables) => voidFunction to initiate message signing.
signMessageAsync(variables: SignMessageVariables) => Promise<SignMessageData>Function to asynchronously sign the message.
...restobjectAdditional mutation state (e.g. isLoading, error, etc.).