[SOLVED] 1inch Plugin not working with buying custom tokens, increase slippage as solution

Hi guys,

Iā€™m having an issue with the 1inch plugin.

Everything is working perfectly when i am trying to sell a custom token eg $BMON to $USDT.

But when i am trying to buy $BMON from $USDT it does not work and i receive the an error. status code:500, cannot estimate, error: internal server error.

When i try to buy with larger amounts i receive ERROR:ERROR something went wrong.


// TRY SWAP
async function trySwap(){

let address = Moralis.User.current().get("ethAddress");  
let amount = Number(document.getElementById("from_amount").value*10**currentTrade.from.decimals);

  
	if(currentTrade.from.symbol !== "BNB"){
      const allowance = await Moralis.Plugins.oneInch.hasAllowance({
        chain: 'bsc', 
        fromTokenAddress: currentTrade.from.address, // The token you want to swap
        fromAddress: address, // Your wallet address
        amount: amount,
      })

      if(!allowance){
        await Moralis.Plugins.oneInch.approve({
          chain: 'bsc', 
          tokenAddress: currentTrade.from.address, 
          fromAddress: address, // Your wallet address
        });
      }
	}
  try {
        let receipt = await doSwap(address, amount);
        console.log("reciept", receipt);
  			alert("SWAP COMPLETE");
        getWalletNativeBalance();//updates the native balane
    
    } 
    catch (error) {console.log("ERROR", error);}
  
}


 
// DO SWAP
function doSwap(address, amount){
 return Moralis.Plugins.oneInch.swap({
      chain:'bsc', 
      fromTokenAddress: currentTrade.from.address,
      toTokenAddress: currentTrade.to.address,
      amount: amount,
      fromAddress: address,
      slippage: slipPercentage,
      type: "native",
	});
} ```

Seem to have solved the issue.

Some a lot of custom tokens require a much higher slippage, When the slippage is increased to 20% the transaction worked fine.

If any one else is having a similar problem. try the same transaction on 1inch and see what it says.

1 Like