> 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/bitcoin-methods/signmessage.md).

# signMessage

Request the signature of an arbitrary message with the first Bitcoin address (Native SegWit or Taproot) of an account

## Method name

`signMessage`

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

## Parameters

<table><thead><tr><th width="188">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>paymentType</td><td>Address type to use. <code>p2wpkh</code> for Native Segwit (default) or <code>p2tr</code> for Taproot.</td><td>false</td><td>string</td></tr><tr><td>type</td><td>Signature format. Leather accepts only <code>bip322</code>, the default.</td><td>false</td><td>string</td></tr><tr><td>network</td><td>Network identifier, for example <code>mainnet</code> or <code>testnet</code>. Defaults to <code>mainnet</code>.</td><td>false</td><td>string</td></tr><tr><td>account</td><td>Index of account for signing. Defaults to the account the app connected with.</td><td>false</td><td>uint</td></tr></tbody></table>

## Example request

```typescript
import { Verifier } from "bip322-js";

try {
  // Request signature
  const response = await window.LeatherProvider.request("signMessage", {
    message: "Hello world",
    paymentType: "p2tr",
    network: "testnet",
    account: 0
  });

  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": "adc296e9-beb7-4685-a443-24c30d0d04dd",
    "result": {
        "signature": "AUDl4ZQJo585ldL0I9S+CjDpT7+5WB2Sspgh47Dsx0WX0iZSCLV+K6smOKJ1u4IUaN6grvNspaZ9GpqPOOHsTTVE",
        "address": "tb1pwfstsmedjfr84rzjsnsjly7x0utzlcfed0uqv26vmwsrvvzuf82qsad4uz",
        "message": "Hello world"
    }
}
```

## 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                              |
| `-32602` | `Unsupported payment type. Leather only supports signing messages for Native Segwit (p2wpkh) and Taproot (p2tr) addresses.` | `paymentType` is not `p2wpkh` or `p2tr`                   |
| `7`      | `This is a Leather sign-in message and its Domain line does not match the requesting origin.`                               | `message` is a Leather sign-in message for another domain |
| `4001`   | `User rejected request`                                                                                                     | The user cancels or 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/79qdnk?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%2FnRyxaZourhSxmCYr03cP%2FSCR-20240419-mgkw.png?alt=media&amp;token=5a217ec0-4783-4f2b-8464-89e643fba2ea" alt=""><figcaption></figcaption></figure>
