How to complete swap method for JustSwap smart-contract

1.5k Views Asked by At

I'am trying to complete JustSwap-contract S-USDT-TRX Token (TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE) But I am getting a response in the console:
REVERT opcode executed
My code:

  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();

I have very good result when I detected price. For example:


      const tx = await tronWebLocal.transactionBuilder.triggerConstantContract(contractToken, `getTokenToTrxOutputPrice(uint256)`, {},
        [{
          type: `uint256`,
          value: 10000000,
        }])

But I can't swap. I am using a connection like this and get error "REVERT opcode executed":

const tx = await tronWebLocal.transactionBuilder.triggerConstantContract(contractToken, `trxToTokenSwapInput(uint256,uint256)`, {}, [{ type: `uint256`, value: },{ type: `uint256`, value: 10}]);

Could you help me make the correct code?

Thank you very much!

1

There are 1 best solutions below

0
On

triggerConstantContract is to Trigger the constant of the smart contract and the transaction is off the blockchain. You can only read the contract by this.(Say price in your case).

Try this : https://developers.tron.network/reference#triggersmartcontract

Format: tronWeb.transactionBuilder.triggerSmartContract(contractAddress,functions, options,parameter,issuerAddress);