PumpSwapRouter: TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB (Launched to Dex)
1. swapExactETHForTokens Function
Description: This function swaps an exact amount of ETH for as many output tokens as possible, along the route determined by the path.
Function Signature:
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)
Parameters:
amountOutMin: The minimum amount of output tokens that must be received for the transaction not to revert.
path: An array of token addresses. path.length must be at least 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to: Address to receive the output tokens.
deadline: Unix timestamp after which the transaction will revert.
TRX Requirement: This function requires you to send ETH as the call value, which will be swapped for the tokens.
Example Call:
const tronWeb = require('tronweb');
const contractAddress = 'TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB';
const amountOutMin = 100 * 1e6; // Example minimum amount of tokens to receive
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
const swapExactETHForTokens = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.swapExactETHForTokens(amountOutMin, path, to, deadline).send({
callValue: tronWeb.toSun(1) // Example: sending 1 TRX
});
};
swapExactETHForTokens();
2. swapTokensForExactETH Function
Description: This function swaps an exact amount of tokens for as much ETH as possible.
Function Signature:
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)
Parameters:
amountOut: The exact amount of ETH to receive.
amountInMax: The maximum amount of input tokens that can be required before the transaction reverts.
path: An array of token addresses. The first address must be the input token, and the last address must be WETH.
to: Address to receive the ETH.
deadline: Unix timestamp after which the transaction will revert.
Example Call:
const amountOut = tronWeb.toSun(1); // 1 TRX
const amountInMax = 200 * 1e6; // Example maximum amount of tokens to send
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
const swapTokensForExactETH = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.swapTokensForExactETH(amountOut, amountInMax, path, to, deadline).send();
};
swapTokensForExactETH();
3. swapExactTokensForETH Function
Description: This function swaps an exact amount of tokens for as much ETH as possible.
Function Signature:
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)
Parameters:
amountIn: The exact amount of input tokens to send.
amountOutMin: The minimum amount of ETH that must be received for the transaction not to revert.
path: An array of token addresses. The first address must be the input token, and the last address must be WETH.
to: Address to receive the ETH.
deadline: Unix timestamp after which the transaction will revert.
Example Call:
const amountIn = 200 * 1e6; // Example amount of tokens to send
const amountOutMin = tronWeb.toSun(0.5); // Example minimum amount of ETH to receive
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
const swapExactTokensForETH = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.swapExactTokensForETH(amountIn, amountOutMin, path, to, deadline).send();
};
swapExactTokensForETH();
4. swapETHForExactTokens Function
Description: This function swaps an exact amount of ETH for as few input tokens as possible.
Function Signature:
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)
Parameters:
amountOut: The exact amount of tokens to receive.
path: An array of token addresses. The first address must be WETH, and the last address must be the output token.
to: Address to receive the tokens.
deadline: Unix timestamp after which the transaction will revert.
TRX Requirement: This function requires you to send ETH as the call value, which will be swapped for the tokens.
Example Call:
const amountOut = 200 * 1e6; // Example amount of tokens to receive
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
const swapETHForExactTokens = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.swapETHForExactTokens(amountOut, path, to, deadline).send({
callValue: tronWeb.toSun(1) // Example: sending 1 TRX
});
};
swapETHForExactTokens();
5. getAmountOut Function
Description: This function calculates the maximum output amount of a token given an input amount of another token.
Function Signature:
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut)
Parameters:
amountIn: The amount of input tokens.
reserveIn: The reserve of the input token in the pair.
reserveOut: The reserve of the output token in the pair.
Example Call:
const amountIn = 100 * 1e6; // Example input amount
const reserveIn = 500 * 1e6; // Example reserve of the input token
const reserveOut = 1000 * 1e6; // Example reserve of the output token
const getAmountOut = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const amountOut = await contract.getAmountOut(amountIn, reserveIn, reserveOut).call();
console.log('Output Amount:', amountOut);
};
getAmountOut();
6. getAmountIn Function
Description: This function calculates the required input amount of a token given an output amount of another token.
Function Signature:
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn)
Parameters:
amountOut: The desired amount of output tokens.
reserveIn: The reserve of the input token in the pair.
reserveOut: The reserve of the output token in the pair.
Example Call:
const amountOut = 100 * 1e6; // Example output amount
const reserveIn = 500 * 1e6; // Example reserve of the input token
const reserveOut = 1000 * 1e6; // Example reserve of the output token
const getAmountOut = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const amountOut = await contract.getAmountIn(amountOut, reserveIn, reserveOut).call();
console.log('Output Amount:', amountOut);
};
7. isAllowedTradingPair Function
Description
The isAllowedTradingPair function determines whether a given trading pair of tokens is allowed for trading. This function is typically used to enforce trading policies or restrictions on specific pairs of tokens within a decentralized exchange or trading platform.
Function Signature:
function isAllowedTradingPair(address tokenA, address tokenB) external view returns (bool);
Parameters:
tokenA: The address of the first token in the trading pair.
tokenB: The address of the second token in the trading pair.
Example Call:
const contractAddress = 'YOUR_CONTRACT_ADDRESS_HERE';
const tokenA = 'TOKEN_A_ADDRESS_HERE'; // Replace with the address of token A
const tokenB = 'TOKEN_B_ADDRESS_HERE'; // Replace with the address of token B
const checkTradingPair = async () => {
try {
const contract = await tronWeb.contract(abi, contractAddress);
const isAllowed = await contract.isAllowedTradingPair(tokenA, tokenB).call();
console.log(`Trading pair (${tokenA}, ${tokenB}) allowed:`, isAllowed);
} catch (error) {
console.error('Error checking trading pair:', error);
}
};
checkTradingPair();
PumpSmartExchangeRouter: TSiiYf1b1PV1fpT9T7V4wy11btsNVajw1g (Launched to Dex)
1.swapExactInput Function
Description
The swapExactInput function is the unified entrance for swaps.
** Only Allow Pump created token and TRX trading pair, using to determine if a pair is allowed for trade. Else transaction will revert.
** Use the to getPair address, then from the Pair address getReserves for token0 & token1
** Contract ABIs are available on TronScan