# 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="https://2085786563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F41U87FfDFo2dIKYr0ZNX%2Fuploads%2FPjFwkp5Kr2HEYEEbuUCz%2FSCR-20240422-nfvj.png?alt=media&#x26;token=b02e04d3-2f5b-45d3-8a4b-a636c139693a" alt=""><figcaption></figcaption></figure>
