> For the complete documentation index, see [llms.txt](https://docs.leather.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.leather.io/developers/stacks-methods/stx_signmessage.md).

# stx\_signMessage

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

## Method name

`stx_signMessage`

The app must be connected first, through [`getAddresses`](/developers/methods/getaddresses.md). Leather signs with the account the app connected with.

## 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>Message for signing. For <code>structured</code>, a hex-encoded serialized Clarity value.</td><td>true</td><td>string</td></tr><tr><td>messageType</td><td>Type of message for signing: <code>utf8</code> (default) for a plain 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>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>, as a hex-encoded serialized Clarity value. Required when <code>messageType</code> is <code>structured</code>.</td><td>false</td><td>string</td></tr><tr><td>network</td><td>Network identifier, for example <code>mainnet</code>, <code>testnet</code>, <code>devnet</code> or <code>mocknet</code></td><td>false</td><td>string</td></tr></tbody></table>

For a structured message you can also call [`stx_signStructuredMessage`](/developers/stacks-methods/stx_signstructuredmessage.md).

## Example request

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

  console.log("Signature:", response.result.signature);
  console.log("Public key:", response.result.publicKey);
} 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",
        "publicKey": "..."
    }
}
```

## Errors

| Code     | Message                                                                                       | When                                                             |
| -------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| `16`     | `Wallet no longer available. Reconnect the app to an available wallet.`                       | The origin is not connected                                      |
| `-32602` | Parameter validation details                                                                  | A parameter fails validation                                     |
| `7`      | `This is a Leather sign-in message and its Domain line does not match the requesting origin.` | A `utf8` message is a Leather sign-in message for another domain |
| `4001`   | `User denied signing`                                                                         | The user selects Cancel                                          |
| `4001`   | `User rejected request`                                                                       | The user closes the window                                       |

## Sandbox

[Install the Leather extension](https://chromewebstore.google.com/detail/leather/ldinpeekobnhjjdofggfgjlcehhmanlj) 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="https://2085786563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F41U87FfDFo2dIKYr0ZNX%2Fuploads%2FPjFwkp5Kr2HEYEEbuUCz%2FSCR-20240422-nfvj.png?alt=media&amp;token=b02e04d3-2f5b-45d3-8a4b-a636c139693a" alt=""><figcaption></figcaption></figure>
