Socket supports swapping assets from any EVM chain to Tron and from Tron to any EVM chain.
This guide walks you through swapping assets between EVM chains and Tron using Socket. It covers transaction options and current limitations.
Quick Start
Key differences
Here’s what’s different when integrating Tron compared to standard EVM chains:
Transaction Flow
User sends funds to a Deposit contract with the quote ID
Socket indexes the transaction and delivers the funds on the destination chain
API Behavior
Both userAddress and receiverAddress required for quotes
The only asset supported from/to Tron is Tron USDT
There is no Fee collection at the moment
Integration Steps
Select Chains: Users choose the source and destination chains, which determine the tokens available for bridging.
Fetch Routes: Retrieve the deposit route if available using the /quote endpoint.
Submit via Deposit contract: Obtain the transaction data from the /quote endpoint. Use this data to execute the deposit transaction on the source chain.
Track Transaction Status: Monitor the transaction’s progress by polling the /status endpoint until the bridging process is complete.
For Tron quotes, please ensure both userAddress and receiverAddress are defined. This is a separate route from autoRoute since it is under depositRoute.
Examples
Queries
Quote from Polygon USDC to Tron USDT
https://public-backend.bungee.exchange/api/v1/bungee/quote?userAddress=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&receiverAddress=TMe1CS54poswoTTrPAtqsKhry4RM7nvSF4&originChainId=137&destinationChainId=728126428&inputToken=0x3c499c542cef5e3811e1192ce70d8cc03d5c3359&outputToken=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t&inputAmount=5000000
Quote from Tron USDT to Base USDC
https://public-backend.bungee.exchange/api/v1/bungee/quote?userAddress=TMe1CS54poswoTTrPAtqsKhry4RM7nvSF4&receiverAddress=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&originChainId=728126428&destinationChainId=8453&inputToken=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t&outputToken=0x833589fcd6edb6e08f4c7c32d4f71b54bda02913&inputAmount=9681288
Scripts
Quote and swap from Tron USDT to Polygon USDC (tronweb)
import { privateKeyToAccount } from "viem/accounts" ;
import { TronWeb } from "tronweb" ;
if ( ! process . env . PRIVATE_KEY ) {
console . error ( "Error: PRIVATE_KEY environment variable is not set" );
process . exit ( 1 );
}
if ( ! process . env . TRON_PRIVATE_KEY ) {
console . error ( "Error: TRON_PRIVATE_KEY environment variable is not set" );
process . exit ( 1 );
}
const account = privateKeyToAccount ( ` ${ process . env . PRIVATE_KEY } ` );
const tronPrivateKey = process . env . TRON_PRIVATE_KEY . replace ( / ^ 0x/ , "" );
const tronWeb = new TronWeb ({
fullHost: "https://api.trongrid.io" ,
privateKey: tronPrivateKey ,
});
const tronAddress = tronWeb . address . fromPrivateKey ( tronPrivateKey );
const BUNGEE_API_BASE_URL = "https://public-backend.bungee.exchange" ;
const USDT_CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" ;
async function getUSDTBalance () {
const contract = await tronWeb . contract (). at ( USDT_CONTRACT );
const balance = await contract . balanceOf ( tronAddress ). call ();
return balance . toString ();
}
async function getQuote ( params ) {
const url = ` ${ BUNGEE_API_BASE_URL } /api/v1/bungee/quote` ;
const fullUrl = ` ${ url } ? ${ new URLSearchParams ( params ) } ` ;
const response = await fetch ( fullUrl );
const data = await response . json ();
const serverReqId = response . headers . get ( "server-req-id" );
if ( ! data . success ) {
throw new Error ( `Quote error: ${ data . statusCode } : ${ data . message } . server-req-id: ${ serverReqId } ` );
}
if ( ! data . result . depositRoute ) {
throw new Error ( `No depositRoute available. server-req-id: ${ serverReqId } ` );
}
return {
quoteId: data . result . depositRoute . quoteId ,
txData: data . result . depositRoute . txData ,
fullResponse: data ,
};
}
async function main () {
const usdtBalance = await getUSDTBalance ();
console . log ( "USDT Balance:" , usdtBalance );
const quoteResponse = await getQuote ({
userAddress: tronAddress ,
receiverAddress: account . address ,
originChainId: 728126428 ,
destinationChainId: 137 ,
inputToken: USDT_CONTRACT ,
outputToken: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359" ,
inputAmount: usdtBalance ,
});
// Submit via tronweb and poll /status with quoteResponse.quoteId
console . log ( "Quote ID:" , quoteResponse . quoteId );
}
main ();