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

# stx\_signMessage

Requests the connected wallet to sign a plaintext message with the user's Stacks private key.

***

### Usage

```ts
import { request } from '@stacks/connect';

const result = await request('stx_signMessage', {
  message: 'Hello, Stacks!',
});

console.log('Signature:', result.signature);
console.log('Public Key:', result.publicKey);
```

#### Notes

* The wallet displays the message to the user for review before signing.
* The resulting signature can be verified using the returned `publicKey`.
* For signing structured data (SIP-018 compliant), use [`stx_signStructuredMessage`](/reference/stacks.js/stacks-connect/methods/stx_signstructuredmessage.md) instead.

[**Reference Link**](https://github.com/stx-labs/connect/blob/main/packages/connect/src/methods.ts#L102)

***

### Signature

```ts
function request(
  'stx_signMessage',
  params: SignMessageParams
): Promise<SignMessageResult>
```

***

### Returns

`SignMessageResult`

```ts
interface SignMessageResult {
  signature: string;
  publicKey: string;
}
```

| Property    | Type     | Description                                  |
| ----------- | -------- | -------------------------------------------- |
| `signature` | `string` | The hex-encoded DER signature.               |
| `publicKey` | `string` | The hex-encoded public key used for signing. |

***

### Parameters

#### message (required)

* **Type**: `string`

The plaintext message string to sign.

#### publicKey (optional, experimental)

* **Type**: `string`

A non-standard parameter to specify which public key to use for signing. Its usage is not recommended as it may not be supported by all wallets. This parameter may be removed in future versions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stacks.co/reference/stacks.js/stacks-connect/methods/stx_signmessage.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
