LaunchpadProxy: TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw (Bonding Curve Period)
** 获取 ABI 代码:
1. createAndInitPurchase Function
描述:
此函数允许创建一个新代币,并立即发起该代币的购买操作。
函数定义:
function createAndInitPurchase(string memory name, string memory symbol) external payable nonReentrant onlyActive
参数:
TRX 需求:
你必须发送不少于 mintFee TRX 的调用金额用于铸造该代币。
示例:
在此示例中,80 TRX 减去 1% 的手续费将用于初始购买该代币。
const tronWeb = require('tronweb');
const contractAddress = 'TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw';
const name = 'MyToken';
const symbol = 'MTK';
const callValue = 100 * 1e6; // 100 TRX, adjust based on the required mintFee
const createAndInitPurchase = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.createAndInitPurchase(name, symbol).send({
callValue: callValue
});
};
createAndInitPurchase();
2. purchaseToken Function
描述:
函数定义:
function purchaseToken(address token, uint256 AmountMin) public payable nonReentrant onlyActive
参数:
AmountMin
: 您期望从购买中获得的最小代币数量。
TRX 需求:
您必须发送至少 minTxFee TRX 作为购买的调用值。
相关辅助函数:
getTokenAmountByPurchaseWithFee
: 使用此函数在购买之前计算预计的代币数量和费用。
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const minTokensExpected = 1000 * 1e6; // Adjust based on the minimum tokens expected
const purchaseToken = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const trxAmount = 50 * 1e6; // 50 TRX, adjust as needed
await contract.purchaseToken(tokenAddress, minTokensExpected).send({
callValue: trxAmount
});
};
purchaseToken();
3. saleToken Function
描述:
函数定义:
function saleToken(address token, uint256 tokenAmount, uint256 AmountMin) external nonReentrant onlyActive
参数:
AmountMin
: 您预期从出售中获得的最小 TRX 数量。
相关辅助函数:
getTrxAmountBySaleWithFee
: 使用此函数在出售前计算预估的 TRX 数量和手续费。
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const tokensToSell = 1000 * 1e6; // Amount of tokens to sell, adjust as needed
const minTrxExpected = 50 * 1e6; // Adjust based on the minimum TRX expected
const saleToken = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.saleToken(tokenAddress, tokensToSell, minTrxExpected).send();
};
saleToken();
4. getPrice Function
描述:
函数定义 :
function getPrice(address token) external view returns (uint256)
参数:
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const getPrice = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const price = await contract.getPrice(tokenAddress).call();
console.log('Current Price:', price);
};
getPrice();
5. getTokenState Function
描述:
函数定义:
function getTokenState(address token) public view returns (uint256)
参数:
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const getTokenState = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const state = await contract.getTokenState(tokenAddress).call();
console.log('Token State:', state);
};
getTokenState();
6. getTokenAmountByPurchaseWithFee Function
描述:
此功能估算在购买代币时你将获得的代币数量及相关费用。
函数定义:
function getTokenAmountByPurchaseWithFee(address token, uint256 trxAmount) public view returns (uint256 tokenAmount, uint256 fee)
参数:
trxAmount
: 您计划花费的 TRX 数量。
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const trxAmount = 50 * 1e6; // 50 TRX, adjust as needed
const getTokenAmountByPurchaseWithFee = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const { tokenAmount, fee } = await contract.getTokenAmountByPurchaseWithFee(tokenAddress, trxAmount).call();
console.log('Estimated Tokens:', tokenAmount, 'Fee:', fee);
};
getTokenAmountByPurchaseWithFee();
7. getExactTokenAmountForPurchaseWithFee Function
描述:
此功能计算购买指定代币数量所需的确切 TRX 数量及相关费用。
函数定义:
function getExactTokenAmountForPurchaseWithFee(address token, uint256 tokenAmount) public view returns (uint256 trxAmount, uint256 fee)
参数:
tokenAmount
: 您希望购买的代币的指定数量。
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const tokenAmount = 1000 * 1e6; // Amount of tokens to purchase, adjust as needed
const getExactTokenAmountForPurchaseWithFee = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const { trxAmount, fee } = await contract.getExactTokenAmountForPurchaseWithFee(tokenAddress, tokenAmount).call();
console.log('Required TRX:', trxAmount, 'Fee:', fee);
};
getExactTokenAmountForPurchaseWithFee();
8. getTrxAmountBySaleWithFee Function
描述:
此函数估算当卖出指定数量的代币时,您将收到的TRX数量及相关费用。
函数定义:
function getTrxAmountBySaleWithFee(address token, uint256 tokenAmount) public view returns (uint256 trxAmount, uint256 fee)
参数:
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const tokenAmount = 1000 * 1e6; // Amount of tokens to sell, adjust as needed
const getTrxAmountBySaleWithFee = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const { trxAmount, fee } = await contract.getTrxAmountBySaleWithFee(tokenAddress, tokenAmount).call();
console.log('Estimated TRX:', trxAmount, 'Fee:', fee);
};
getTrxAmountBySaleWithFee();
9. getExactTrxAmountForSaleWithFee Function
描述:
此函数计算获取指定数量 TRX 所需的确切代币数量及相关费用。
函数定义:
function getExactTrxAmountForSaleWithFee(address token, uint256 trxAmount) public view returns (uint256 tokenAmount, uint256 fee)
参数:
trxAmount
: 您希望接收的指定 TRX 数量。
示例:
const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const trxAmount = 50 * 1e6; // Amount of TRX to receive, adjust as needed
const getExactTrxAmountForSaleWithFee = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
const { tokenAmount, fee } = await contract.getExactTrxAmountForSaleWithFee(tokenAddress, trxAmount).call();
console.log('Required Tokens:', tokenAmount, 'Fee:', fee);
};
getExactTrxAmountForSaleWithFee();
PumpSwapRouter: TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB (Launched to Dex)
** 只允许 Pump 创建的代币与 TRX 的交易对,使用 Sunpump 合约来确定交易对是否被允许进行交易。否则,交易将会被回退。
** 合约 ABI 可以在 TronScan 上找到。
1. swapExactETHForTokens Function
描述:
此函数将指定数量的 TRX 兑换为尽可能多的输出代币,兑换路线由路径确定。
函数定义:
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)
参数:
amountOutMin
: 交易不会回滚的情况下,必须接收的最小输出代币数量。
path
: 一个代币地址的数组。path.length 必须至少为 2。每一对连续地址之间的池子必须存在并且具有流动性。
deadline
: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。
TRX 需求:
此函数要求您发送 TRX 作为调用值,TRX 将被兑换为代币。
示例:
2. swapTokensForExactETH Function
描述:
函数定义:
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)
参数:
amountOut
: 要接收的指定 TRX 数量。
amountInMax
: 在交易回退之前可以要求的最大输入代币数量。
path
: 一个代币地址的数组。第一个地址必须是输入代币地址,最后一个地址必须是 WTRX 地址。
deadline
: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。
示例:
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
描述:
函数定义:
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)
参数:
amountOutMin
: 为防止交易回滚,必须接收的最低 TRX 数量。
path
: 一个代币地址数组。第一个地址必须是输入代币地址,最后一个地址必须是 WTRX 地址。
deadline
: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。
示例:
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
描述:
函数定义:
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)
参数:
path
: 一个代币地址数组。第一个地址必须是 WTRX 地址,最后一个地址必须是输出代币地址。
deadline
: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。
TRX 需求:
此函数要求您发送 TRX 作为调用值,这些 TRX 将被交换为代币。
示例:
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
描述:
函数定义:
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut)
参数:
reserveOut
: 交易对中输出代币的储备量。
示例:
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
描述:
函数定义:
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn)
参数:
reserveOut
: 交易对中输出代币的储备量。
示例:
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
描述
isAllowedTradingPair
函数用于确定给定的代币交易对是否允许交易。此函数通常用于在去中心化交易所或交易平台内执行针对特定代币对的交易政策或限制。
函数定义:
function isAllowedTradingPair(address tokenA, address tokenB) external view returns (bool);
参数:
示例:
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)
描述
swapExactInput
函数是交换操作的统一入口。
函数定义:
function swapExactInput(
address[] calldata path,
string[] calldata poolVersion,
uint256[] calldata versionLen,
uint24[] calldata fees,
SwapData calldata data
) external nonReentrant payable returns (uint256[] memory amountsOut)
struct SwapData {
uint256 amountIn;
uint256 amountOutMin;
address to;
uint256 deadline;
}
参数:
poolVersion
: 路径中代币池子版本列表。
versionLen
: poolVersion 中代币池子版本的长度列表。
fees
: 池的费用列表,仅支持 SUNSWAP V3 池。
data
: 交换信息,使用 SwapData
结构,获取 amountIn
(输入代币数量)、amountOutMin
(最小输出数量)、接收者地址(to
)和截止时间(deadline
)。
示例:
const tronWeb = require('tronweb');
const contractAddress ='TSiiYf1b1PV1fpT9T7V4wy11btsNVajw1g
';
const amountOutMin =YOUR_TOKEN_AMOUNT_MIN; // Example minimum amount of tokens to receive
const pathTrxToToken = [address(0),WTRX,TokenAddress]; // Example path
const pathTokenToTrx = [tokenAddress,WTRX,address(0)];
const poolVersion = ["v2"];
const versionLen = ["3"];
const fees = [0,0,0];
const amountIn = YOUR_TOKEN_AMOUNT
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
const swapdata = [amountIn,amountOutMin,to,deadline];
// trx - token
const swapExactInput = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.swapExactInput(
pathTrxToToken,
poolVersion,
versionLen,
fees,
swapdata
).send({
callValue: tronWeb.toSun(amountIn) // Example: sending 1 TRX
});
};
// token -trx
const swapExactInput = async () => {
const contract = await tronWeb.contract(abi, contractAddress);
await contract.swapExactInput(
pathTokenToTrx,
poolVersion,
versionLen,
fees,
swapdata
).send();
};