# Sign Message

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://api.g.alchemy.com/signer/v1/sign-payload

Allows for the signing of arbitrary payloads using the authenticated user's signer. The payload to be signed should be included within the body of a stamped request, ensuring the integrity and authenticity of the message to be signed. This operation is important for executing transactions and interactions on the blockchain that require verified signatures from the user's wallet.


Reference: https://www.alchemy.com/docs/wallets/api-reference/signer/signer-api-endpoints/sign-message

## Headers

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Authorization | string | Yes | Bearer token authentication. Use 'Bearer <apiKey>' as the value. |

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://api.g.alchemy.com/signer/v1/sign-payload \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "stampedRequest": {
    "url": "string",
    "body": "string",
    "stamp": {
      "stampHeaderName": "string",
      "stampHeaderValue": "string"
    }
  }
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    stampedRequest: {
      url: 'string',
      body: JSON.stringify('string'),
      stamp: {stampHeaderName: 'string', stampHeaderValue: 'string'}
    }
  })
};

fetch('https://api.g.alchemy.com/signer/v1/sign-payload', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.g.alchemy.com/signer/v1/sign-payload"

payload = { "stampedRequest": {
        "url": "string",
        "body": "string",
        "stamp": {
            "stampHeaderName": "string",
            "stampHeaderValue": "string"
        }
    } }
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.g.alchemy.com/signer/v1/sign-payload"

	payload := strings.NewReader("{\n  \"stampedRequest\": {\n    \"url\": \"string\",\n    \"body\": \"string\",\n    \"stamp\": {\n      \"stampHeaderName\": \"string\",\n      \"stampHeaderValue\": \"string\"\n    }\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://api.g.alchemy.com/signer/v1/sign-payload")
  .header("Content-Type", "application/json")
  .header("Authorization", "Bearer <token>")
  .body("{\n  \"stampedRequest\": {\n    \"url\": \"string\",\n    \"body\": \"string\",\n    \"stamp\": {\n      \"stampHeaderName\": \"string\",\n      \"stampHeaderValue\": \"string\"\n    }\n  }\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://api.g.alchemy.com/signer/v1/sign-payload");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "Bearer <token>");
request.AddJsonBody("{\n  \"stampedRequest\": {\n    \"url\": \"string\",\n    \"body\": \"string\",\n    \"stamp\": {\n      \"stampHeaderName\": \"string\",\n      \"stampHeaderValue\": \"string\"\n    }\n  }\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## Operation Specification

```yaml
path: /sign-payload
method: POST
operation:
  summary: Sign Message
  description: |
    Allows for the signing of arbitrary payloads using the authenticated user's signer. The payload to be signed should be included within the body of a stamped request, ensuring the integrity and authenticity of the message to be signed. This operation is important for executing transactions and interactions on the blockchain that require verified signatures from the user's wallet.
  security:
    - apiKey: []
  x-readme:
    samples-languages:
      - javascript
      - curl
      - python
      - go
  requestBody:
    content:
      application/json:
        schema:
          type: object
          properties:
            stampedRequest:
              description: |
                A stamped request that includes the payload to be signed. The payload is part of the stamped request's body, which should conform to the structure outlined in the Turnkey API documentation for signing raw payloads.

                Because users are given wallets for both Ethereum and Solana, it's possible to request signatures for both chains. The following is an example of the payload structure for signing bytes on Ethereum and Solana:

                Signing bytes for Ethereum:
                ```
                {
                  organizationId: this.user.orgId,
                  type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
                  timestampMs: Date.now().toString(),
                  parameters: {
                    encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
                    hashFunction: "HASH_FUNCTION_NO_OP",
                    payload: msg,
                    signWith: this.user.address,
                  },
                }
                ```

                Signing bytes for Solana:
                ```
                {
                  organizationId: this.user.orgId,
                  type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
                  timestampMs: Date.now().toString(),
                  parameters: {
                    encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
                    hashFunction: "HASH_FUNCTION_NOT_APPLICABLE",
                    payload: msg,
                    signWith: this.user.solanaAddress,
                  },
                }
                ```

                For more details on the parameters of the request body, see [Turnkey's API Reference](https://docs.turnkey.com/api#tag/Signing/operation/SignRawPayload).
              type: object
              properties:
                url:
                  type: string
                  description: Generated by the turnkey client, but will be ignored on our end.
                body:
                  type: string
                  description: JSON stringified request body.
                stamp:
                  type: object
                  description: |
                    A JSON-encoded object containing stamping information.
                  properties:
                    stampHeaderName:
                      type: string
                      description: |
                        For WebAuthN based stamps, this should be `X-Stamp-Webauthn`. For all other stamps, this should be `X-Stamp`.
                    stampHeaderValue:
                      type: string
                      description: |
                        The stamp over the request body. See the [Turnkey Stamps Documentation](https://docs.turnkey.com/api-design/stamps) for information on the format of this value.
                  required:
                    - stampHeaderName
                    - stampHeaderValue
              required:
                - body
                - stamp
          required:
            - stampedRequest
  responses:
    '200':
      description: Message signing successful.
      content:
        application/json:
          schema:
            type: object
            properties:
              signature:
                type: string
                description: The signature generated for the specified payload.
            required:
              - signature
  operationId: signMessage
```
