# stx\_signMessage

## Method name

`stx_signMessage`

## Parameters

<table><thead><tr><th width="186">Parameter</th><th width="376">Description</th><th width="101" data-type="checkbox">Required</th><th width="83">Type</th></tr></thead><tbody><tr><td>message</td><td>Arbitrary message for signing</td><td>true</td><td>string</td></tr><tr><td>messageType</td><td>Type of message for signing: <code>utf8</code> for basic string or <code>structured</code> for <a href="https://github.com/stacksgov/sips/blob/main/sips/sip-018/sip-018-signed-structured-data.md">structured data</a>.</td><td>true</td><td>string</td></tr><tr><td>network</td><td>Network for signing: <code>mainnet</code>, <code>testnet</code> (default), <code>signet</code>, <code>sbtcDevenv</code> or <code>devnet</code></td><td>false</td><td>string</td></tr><tr><td>domain</td><td><a href="https://github.com/stacksgov/sips/blob/main/sips/sip-018/sip-018-signed-structured-data.md#formal-specification">Domain tuple per SIP-018</a> (for structured messages only)</td><td>false</td><td>string</td></tr></tbody></table>

## Example request

```typescript
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

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

## Sandbox

[Install the Leather extension](https://leather.io/install-extension) then try out this method below:

{% embed url="<https://codesandbox.io/embed/5mtlj8?expanddevtools=1&hidenavigation=1&module=/src/index.ts&view=preview>" %}

## Preview

<figure><img src="/files/vjl41T4PCwVrfxj5gNQm" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://leather.gitbook.io/developers/stacks-methods/stx_signmessage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
