我正在尝试完成JustSwap-contract S-USDT-TRX令牌(TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE)但我在控制台中得到响应:
REVERT opcode executed
代码:
const TronWeb = require("tronweb");
const ethers = require("ethers")
const MAINNET_RPC = "https://api.trongrid.io";
const PLACEHOLDER_PRIVATE_KEY = "YOUR_PRIVATE_KEY";
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider(MAINNET_RPC);
const solidityNode = new HttpProvider(MAINNET_RPC);
const eventServer = new HttpProvider(MAINNET_RPC);
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,PLACEHOLDER_PRIVATE_KEY);
const startJustSwap = async () => {
try {
const contractTokenExchangeUSDT = 'TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE'; //S-USDT-TRX Token
const parameters = [{type: `uint256`, value: 10000000},{type: `uint256`,value: 1614346581000}];
const tx = await tronWeb.transactionBuilder.triggerConstantContract(contractTokenExchangeUSDT, `trxToTokenSwapInput(uint256,uint256)`, {},parameters)
console.log(tx);
} catch (e) {
console.log(e);
}
};
startJustSwap();
当我检测价格时,我有很好的结果。例如:
const tx = await tronWebLocal.transactionBuilder.triggerConstantContract(contractToken, `getTokenToTrxOutputPrice(uint256)`, {},
[{
type: `uint256`,
value: 10000000,
}])
但是我不能交换。我正在使用这样的连接,并得到错误"REVERT opcode executed":
const tx = await tronWebLocal.transactionBuilder.triggerConstantContract(contractToken, `trxToTokenSwapInput(uint256,uint256)`, {}, [{ type: `uint256`, value: },{ type: `uint256`, value: 10}]);
你能帮我做正确的代码吗?
非常感谢!
triggerConstantContract是触发智能合约的常数,交易离开区块链。你只能通过这个来阅读合同。(按你的情况说价格)。
试试:https://developers.tron.network/reference#triggersmartcontract
格式:tronWeb.transactionBuilder.triggerSmartContract(contractAddress,functions, options,parameter,issuerAddress);