Here is an article on how to modify the existing Node.js route to return transactions from the TRON network instead of Binance:
Modifying the Binance API Route to Return Transactions from TRON
As a developer working with Ethereum and TRON, you are probably familiar with the Binance public API for retrieving transactions. However, its current implementation returns transactions from the Binance platform. In order to modify this route and return transactions from the TRON network instead, we will need to make some adjustments.
Step 1: Identify Tron API Endpoints
Before we begin, let’s identify the relevant endpoints on the TRON blockchain to retrieve transactions:
- TRC-20 Token Trading API

:
GET /api/v2/trades(returns transaction data for a specific token and pair)
- TRX Token Trading API:
GET /api/v1/trades(returns transaction data for a specific token and pair)
We will use the TRX Token Trading API endpoint as our starting point.
Step 2: Modify the Binance API route to return TRON transactions
To return TRON transactions, we need to make the following changes to your existing route:
- Update the
endpointparameter in theGET /api/v3/tradesresponse to include the new endpoint.
const response = await client.get(${endpoint}/trades);
- Modify the
paramsobject to pass the relevant query parameters, such as:
from: Specifies the token and pair for which you want to retrieve transactions (e.g. TRX/ETH)
to: Specifies the token and pair for which you are interested in retrieving transactions
response = await client.get(${endpoint}/trades?from=TRX&to=ETH);
- Update the
dataproperty of each transaction object to include the relevant information, such as the amount traded.
Step 3: Update the Node.js route code
Here is an example code snippet that demonstrates how the existing route can be modified to return transactions from TRON:
const express = require('express');
const app = express();
const { Client } = require('@truffle/truffle-client'); // Import the Truffle client library
// Set up a new API client instance with the TRX Token Transaction API endpoint and token
const trxClient = new Client({
host: '
token: 'YOUR_TRON_TOKEN'
});
app.get('/trades', async (req, res) => {
try {
const tradesResponse = await trxClient.get(${process.env.TRX_API_ENDPOINT}/trades);
// Loop through each trade and extract relevant information
tradesResponse.data.forEach((trade) => {
// Assuming the trade object has an 'amount' property with the traded amount
console.log(Trade: ${trade.id} - From: TRX, To: ETH, Amount: ${trade.amount});
});
res.json(tradesResponse);
} catch (error) {
console.error(error);
res.status(500).json({ message: 'Error retrieving trades' });
}
});
app.listen(process.env.PORT, () => {
console.log(Server listening on port ${process.env.PORT});
});
In this modified code snippet:
- We create a new API client instance with the TRX token trading API endpoint and token.
- We define a
/tradesroute that returns TRON trades by calling thegetmethod on the TRX client endpoint for the specified trade type (in this case, TRX/ETH).
- We loop through each trade object and extract the relevant information, such as the amount traded.
- Finally, we return the extracted data in a JSON response.
This code snippet demonstrates how you can modify your existing route to return TRON trades. Remember to replace YOUR_TRON_TOKEN with the symbol of your actual Tron token (e.g., TRX).