UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT Sunswap

165 views Asked by At
`const { trx_amount, private_key } = request.body;
var tronWeb = new TronWeb({
  fullHost: "https://api.trongrid.io",
  headers: { "TRON-PRO-API-KEY": "xxxxxxxxxxxxxxxxxxxxxxxxx" },
  privateKey: private_key,
});
let contract = await tronWeb.contract().at("TKzxdSv2FZKQrEqkKVgp5DcwEXBEKMg2Ax");
const currentTime = Math.floor(Date.now() / 1000);
const deadline = currentTime + (20 * 60); // 20 minutes in seconds
try {
  const swap = await contract.methods.swapExactETHForTokens(
    trx_amount,
    [
      "TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR",
      "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
    ],
    "TRpZ1F9xxxxxxxxxxxxxxxxxxxxxxxx",
    deadline
  ).send();
 response.status(200).send({
   hash: swap,
   message: "You swap is under process",
 });
} catch (e) {
  response.status(400).send({
    message: "There was an error",
    error: e,
  });
}`

I am trying to use sunswap, i am not good in blockchain, any help would be appreciated. Transaction is failing happening but with this error UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT

You can check the transaction here

UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT*

1

There are 1 answers

0
Iresh Madhusankha - DevCresix On

Issue is you are calling a payable function without a value. As you are trying to swap TRX to another token you must send TRX to the function, swapExactETHForTokens.

const swap = await contract.methods.swapExactETHForTokens(
trx_amount,
[
  "TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR",
  "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
],
"TRpZ1F9xxxxxxxxxxxxxxxxxxxxxxxx",
deadline
 ).send({value:trx_amount});

Set the params {value:trx_amount} inside send