This is a service that watches for TRON (TRC20) USDT transactions and triggers a webhook when a specific transaction is completed or expired.
Caution
This service is in its early stages of development and is expected to improve significantly over time. While it provides basic functionality for watching TRON (TRC20) USDT transactions, it should not be solely relied upon for production use at this stage. We recommend users to independently save transaction hashes to handle any cases in which transactions are resent by the webhook. Please stay tuned for future updates and improvements.
- Watch TRC20 USDT transactions on the TRON network.
- In-memory storage for watched transactions and processed events using JavaScript's
Map
. - Automatically sends webhooks for completed and expired transactions.
- Uses
express
for routing,helmet
for security, andwinston
for logging.
- Node.js
- Express.js
- TronWeb - To interact with the TRON blockchain.
- BigNumber.js - For handling large numbers in transactions.
- Winston - Logging framework.
- Axios - For sending webhooks.
- Zod - For validation.
- Node.js v14+
- NPM or Yarn
- TRON API Key (for
TronWeb
)
-
Clone the repository:
git clone https://github.com/moha-abdi/TronWatch.git cd TronWatch
-
Install the dependencies:
npm install
-
Create a
.env
file at the root of your project and add the following environment variables:PORT=3000 TRON_FULL_HOST="https://api.trongrid.io" TRON_PRO_API_KEY="your-tron-api-key" USDT_CONTRACT_ADDRESS="TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" USDT_DEPOSIT_ADDRESS="YOUR USDT TRC-20 ADDRESS" API_KEY="your-secure-api-key" WEBHOOK_SECRET="your-secure-webhook-secret"
-
Build the project:
npm run build
-
Run the application:
npm start
For development, use the following command to start the server with ts-node-dev
:
npm run dev
POST /api/watcher/watch
Request body:
{
"id": "unique-transaction-id",
"fromAddress": "TRX-address",
"amount": 100,
"webhookUrl": "https://yourwebhook.com/transaction"
}
DELETE /api/watcher/watch/:id
-
In-Memory Transactions: The service stores watched transactions and processed events in memory using JavaScript's
Map
instead of Redis. -
Watching Transactions: The
TronWatcher
class listens for TRC20Transfer
events from the TRON network. If the transaction matches a watched one, a webhook is triggered. -
Expired Transactions: Transactions are given a 5-minute window to be completed. If they expire, a webhook is sent notifying the user that the transaction has expired.
-
Webhook Notification: When a transaction is completed or expired, the service sends a POST request to the provided webhook URL with details of the transaction.
To ensure secure communication, each webhook request includes an X-Webhook-Signature
header. The signature is generated using HMAC-SHA256 and a secret key (WEBHOOK_SECRET
). This allows the receiving server to verify that the webhook request came from a trusted source.
To generate the signature, the payload is hashed using the WEBHOOK_SECRET
:
import crypto from "crypto";
function generateSignature(payload: string): string {
return crypto
.createHmac("sha256", process.env.WEBHOOK_SECRET!)
.update(payload)
.digest("hex");
}
Feel free to fork this repository and contribute by submitting pull requests. For any major changes, please open an issue first to discuss the changes.