# Registering Errors on Smart Contract Calls

Since we cannot determine if a gas estimation fails on the integrator's side—particularly when called from the integrator's smart contract—we provide an endpoint to register errors that occur during on-chain calls. This information is highly valuable to us for maintaining service quality, allowing us to analyze and review failed trades (e.g., tokens involved, DEX used, and other relevant details).

**Endpoint: `POST /api/register-error`**

This endpoint allows clients to register errors that occur during smart contract calls when conducting a trade. The provided information can include various transaction-related details, though all fields are optional.

***

#### **Request**

* **Method**: `POST`
* **Content-Type**: `application/json`

**Request Body Parameters**

| Field              | Type     | Description                                                                         |
| ------------------ | -------- | ----------------------------------------------------------------------------------- |
| `input_data`       | `string` | (Optional) The raw input data of the transaction.                                   |
| `value`            | `string` | (Optional) The value of the transaction in wei (smallest unit of the native token). |
| `sender`           | `string` | (Optional) The address of the sender initiating the transaction (`0x...`).          |
| `to_address`       | `string` | (Optional) The address to which the transaction is sent (`0x...`).                  |
| `api_key`          | `string` | (Optional) The API key for authentication and tracking.                             |
| `chain_id`         | `number` | (Optional) The ID of the blockchain network where the transaction was conducted.    |
| `block_number`     | `number` | (Optional) The block number where the transaction was attempted.                    |
| `transaction_hash` | `string` | (Optional) The hash of the transaction (`0x...`).                                   |

***

#### **Response**

**Successful Response**

* **HTTP Status**: `200 OK`
* **Response Body**:

  ```json
  {
    "status": "success",
    "message": "Error registered successfully."
  }
  ```

**Error Response**

* **HTTP Status**: `400 Bad Request`
* **Response Body** (example):

  ```json
  {
    "status": "error",
    "message": "Invalid request body."
  }
  ```

***

#### **Example Request**

**Request Body**

```json
{
  "input_data": "0xa9059cbb000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
  "value": "1000000000000000000",
  "sender": "0xAbcd1234Ef567890abcd1234Ef567890Abcd1234",
  "to_address": "0xDefg5678Gh901234defg5678Gh901234Defg5678",
  "api_key": "my-secret-api-key",
  "chain_id": 1,
  "block_number": 12345678,
  "transaction_hash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
}
```

**Response**

```json
jsonCopiar código{
  "status": "success",
  "message": "Error registered successfully."
}
```

***

#### **Notes**

1. **Optional Fields**: All fields in the request are optional; the backend should handle missing fields gracefully.
2. **Error Logging**: This endpoint is used to collect transaction details when an error occurs, providing valuable insights for debugging and analytics.
3. **Authentication**: If the `api-key` is required for security, ensure it is validated against your system.
4. **Chain-Specific Handling**: The `chainId` should correspond to the appropriate blockchain network (e.g., Ethereum Mainnet = `1`).

This documentation entry provides clear guidelines for developers to use the `POST /api/register-error` endpoint effectively.


---

# Agent Instructions: 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:

```
GET https://docs.unizen.io/on-chain-contracts-get-started/registering-errors-on-smart-contract-calls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
