Here is an article about changing the existing Node.js route to return operations from the Tron network instead of Binance:
Change the Binance Api Road to Return Tron Trades
As a creator working with Ethereum and Tron, you are probably familiar with Binance public API to get operations. However, your current conversion returns operations from the Binance platform. To change this route and return operations from the Tron Network, we will have to make several changes.
Step 1: Set Tron API rear points
Before we start, let’s find out the relevant Tron Blockchain rear points to get the transactions:
* TRC-20 token Teading API : Get/API/V2/Trades' (returns trading data to the sector and can)
* TRX Token Trading API :Get/API/V1/Trades’ (returns commercial data to a specific key access key and pair)
We will use TRX Token Trading Api as a starting point.
Step 2: Change Binance Api Road to return tron transactions
To return operations from Tron, we need to make the following changes to your existing route:
- Update the Endpoint parameter in your response.
`Javascript
Const Response = Wait Client.get ($ {Endpoint}/Trades);
- Change the object for the “days” to transfer the appropriate request parameters such as:
* “Out”: indicate the cursor and the pair you want to get transactions (eg TRX/Eth)
* “To”: indicates the marker of your interest and a pair
`Javascript
Answer = wait for customer.get ($ {endpoint}/trade? From = trx & to = eth
);
`
- Update the “data” property to each retail store to include the relevant information such as the amount traded.
Step 3: Update the node route code.js
Here is a sample code fragment showing how you can change your existing path to return the operations from Tron:
`Javascript
CONST EXPRESS = Claim (‘Express’);
CONST App = Express ();
CONST {Customer} = Claim (‘@Trinapho/Triple Customer’); // Import Truffle Customer Library
// Set the new API customer Cinder with TRX Teken Trading API outcome and access key
CONST TRXCLIENT = NEW Customer ({{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
Home PC: ‘ ‘
Access Key: ‘Your_tron_Token’
});
App.get (‘/trades’, async (req, res) => {{{{{{{{{{{{{{{{{{{{{{{
try {
CONST TRADESREPACTION = Wait trxclient.get ($ {process.env.trx_api_ndpoint}/trades);
// View each trade and scan the appropriate information
Tradesresponse.data.freach ((Trade) => {
// By assuming that the retail outlets are the amount of "sum" assets with trading
Console.log (trade: $ {Wead.id} – from: TRX, to: Ethh, sum, sum: $ {Trade.mount});
});
Res.json (Tradesresponse);
} catch (error) {
Console.error (error);
res.status (500) .json ({message: 'Error attracts operations'});
}
});
App .listen (process.env.port, () => {
Console.log (Listen to the server port $ {process.env.port});
});
In this modified fragment of the code:
- We create a new API customer copy with TRX Token Trading Api Endpoint and token.
- We define the “/trading route” that returns the operations from the TRON, calling the “get” method for the TRX customer’s type of trading type (in this case TRX/ETH).
- We miss every retail store and get important information such as the amount traded.
- Finally, we return the data received by response to JSON.
This code fragment shows how you can change the existing path to return the operations from the Tron. Be sure to replace your__tron_tken with your true Tron Tocknorm (eg TRX).