stx_signMessage

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

Method name

stx_signMessage

Parameters

Parameter
Description
Required
Type

message

Arbitrary message for signing

string

messageType

Type of message for signing: utf8 for basic string or structured for structured data.

string

network

Network for signing: mainnet, testnet (default), signet, sbtcDevenv or devnet

string

domain

Domain tuple per SIP-018 (for structured messages only)

string

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

Sandbox

Install the Leather extension then try out this method below:

Preview

Last updated