> For the complete documentation index, see [llms.txt](https://docs.onchainpay.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onchainpay.io/signature.md).

# Request signing

You need to specify your **secret key**, apply `SHA256` encryption to your payload and convert the result to `HEX` format

## Nonce usage

You should pass `nonce` parameter in the payload of every request to this API. `nonce` can be a number or a string, each request must be accompanied by a unique value. Otherwise the request will fail.

We will use Unix TimeStamp as the `nonce` value for sending requests in this document.

## Example of creating request signature `NodeJS`

Let's say we want to get price rate of `ETH`/`USDT` (method `/price-rate`)

**1. Build request payload**

```javascript
const payload = { from: 'ETH', to: 'USDT' };
```

**2. Add** **`nonce`** **parameter to the payload in order to avoid request duplication.**

By using unix timestamp as `nonce` parameter we will meet the requirements of using number and its incrementing for every new request.

```javascript
payload.nonce = Date.now(); // 1643881172430
```

**3. Create string from payload and used it in a process of creating signature.**

```javascript
const stringPayload = JSON.stringify(payload); // {"from":"ETH","to":"USDT","nonce":1643881172430}
```

**4. Create signature:**

Example with `crypto-js` module:

```javascript
const CryptoJS = require("crypto-js"); 
const sign = CryptoJS.HmacSHA256(stringPayload, __PRIVATE_KEY__).toString(CryptoJS.enc.Hex)
```

Example with `crypto` module:

```javascript
const crypto = require('crypto');  
const sign = crypto.createHmac('SHA256', __PRIVATE_KEY__).update(stringPayload).digest('hex');
```

**5. Send request with required headers:**

```javascript
const axios = require('axios'); // lib for HTTP requests
const response = await axios.post(__BASE_URL__ + '/price-rate', stringPayload, 
{ 
    headers: 
        {
            'x-api-public-key': __PUBLIC_KEY__, 
            'x-api-signature': sign 
        } 
});
```

**6. Response:**

```javascript
console.log(response.data); // {"success":true,"response":"2751.51000000"}
```


---

# 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.onchainpay.io/signature.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.
