> 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
