Node.js Guide for Calling Mefree.NET API

This guide explains how to use Node.js to interact with the Mefree.NET API, including signature generation, HTTP requests, and example usage.


1. Overview of the Signature Rules

1.1 Signature String Rules

To authenticate with Mefree.NET API, requests must include a signature. Follow these steps:

  1. Construct the String to Sign:

    sign = timestamp + method + requestPath
    • timestamp: The current UTC timestamp in ISO 8601 format, e.g., 2024-11-26T12:34:56.789Z.

    • method: HTTP method (e.g., GET, POST).

    • requestPath: The API endpoint path, including query parameters if present, such as:

      • /api/config

      • /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1

  2. Generate the Signature:

    • Use the HMAC-SHA256 algorithm to hash the string using your Secret Key.

    • Encode the resulting hash with Base64.


1.2 Required HTTP Headers

Every API request must include the following headers:

  • Content-Type: application/json

  • MF-ACCESS-KEY: Your API Key.

  • MF-ACCESS-SIGN: The signature generated above.

  • MF-ACCESS-TIMESTAMP: Current UTC timestamp.


2. Environment Setup

  1. Ensure you have Node.js installed (version 14+ recommended).

  2. Install the required dependencies:


3. Signature Generation Function

Below is the Node.js function to generate the required signature:


4. Sending HTTP Requests

Use the axios library to send HTTP requests with the required headers.


5. Example API Calls

5.1 Get Account Information

API Endpoint: /api/config HTTP Method: GET

Code Example:


5.2 Create an Order

API Endpoint: /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1 HTTP Method: POST

Code Example:


5.3 Query Order Status

API Endpoint: /api/order/{pay_hash} HTTP Method: GET

Code Example:


6. Common Issues

6.1 Invalid Signature (401 Unauthorized)

  • Double-check the MF-ACCESS-KEY matches your API Key.

  • Verify the signature generation logic:

    • Ensure the string format is timestamp + method + requestPath.

    • Use the correct SECRET_KEY.

  • Ensure the timestamp is in UTC format and not older than 5 seconds.

6.2 Bad Request (400)

  • Check that the request path and query parameters are correct.

  • Ensure the Content-Type header is set to application/json.

6.3 Too Many Requests (429)

  • Respect the API rate limits. Add throttling in your code if necessary.


7. Summary

This guide demonstrates how to interact with the Mefree.NET API using Node.js. It includes the signature generation logic, HTTP request handling, and examples for common API calls. For additional support, refer to the official API documentation or contact Mefree support.

Last updated