APIs

Developer Docs

stx_signMessage API method

May 22, 2025

Disclaimer: Leather does not verify how message signatures are used. Developers are responsible for correct usage and signature verification.

stx_signMessage

Request the signature of an arbitrary message with the Stacks address of an account.

Method name

stx_signMessage

Parameters

  • message (string, required): Arbitrary message to be signed.

  • messageType (string, optional): utf8 for basic string or structured for SIP-018 structured data.

  • network (string, optional): Target network (testnet is default). Supports mainnet, testnet, signet, sbtcDevenv, devnet.

  • domain (string, optional): Required only for structured messages. Follows SIP-018 domain tuple.

Example request

try {
  // Request signature
  const response = await window.LeatherProvider.request("stx_signMessage", {
    message: "Hello world",
    messageType: "utf8",
    network: "testnet",
  });

  console.log("Response:", response);

  // Verify signature
  try {
    const isValid = Verifier.verifySignature(
      response.result.address,
      response.result.message,
      response.result.signature
    );
    console.log("Signature is valid: ", isValid);
  } catch (error) {
    console.log("Verification error:", error);
  }
} catch (error) {
  console.log("Request error:", error.error.code, error.error.message);
}

Example response

{
  "jsonrpc": "2.0",
  "id": "7d0e6f7f-3ecf-4cc4-b555-80d1e4102d01",
  "result": {
    "signature": "8d33430a7b017ba29af2410cd7e0e79edd44e004a8611132fcfa475244b00dcf72972e15ebde4a72efca1dd628414e28bfaf495098bf0506664eee54e811b20801"
  }
}

Sandbox

To try this live in a prebuilt example, open the stx_signMessage sandbox on CodeSandbox.

Make sure the Leather extension is installed and running.