> 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_signstructuredmessage.md).

# stx\_signStructuredMessage

Request the signature of a structured message using the Stacks address of an account.

## Method name

`stx_signStructuredMessage`

The app must be connected first, through [`getAddresses`](/developers/methods/getaddresses.md). Leather signs with the account the app connected with. The same request through [`stx_signMessage`](/developers/stacks-methods/stx_signmessage.md) with `messageType: "structured"` gives the same result.

## Parameters

| Parameter | Description                                                                                              | Required | Type     |
| --------- | -------------------------------------------------------------------------------------------------------- | -------- | -------- |
| `message` | The structured message to sign, as a hex-encoded serialized Clarity value                                | ✅        | `string` |
| `domain`  | The domain tuple that defines the signing context per SIP-018, as a hex-encoded serialized Clarity value | ✅        | `string` |

## Example request

```typescript
import { serializeCV, stringAsciiCV, tupleCV, uintCV } from "@stacks/transactions"; // 7.x

const domain = serializeCV(
  tupleCV({
    name: stringAsciiCV("My App"),
    version: stringAsciiCV("1.0.0"),
    "chain-id": uintCV(1), // mainnet
  })
);
const message = serializeCV(stringAsciiCV("Hello world"));

try {
  const response = await window.LeatherProvider.request("stx_signStructuredMessage", {
    message,
    domain,
  });

  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

```json
{
  "jsonrpc": "2.0",
  "id": "a1b2c3d4-e5f6-7890-1234-56789abcdef0",
  "result": {
    "signature": "<signature hex>",
    "publicKey": "<public key hex>"
  }
}
```

## 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 |
| `4001`   | `User denied signing`                                                   | The user selects Cancel      |
| `4001`   | `User rejected request`                                                 | The user closes the window   |
