Not enough allowance 1Inch swap

Hello, i am trying to build a simple dex using Moralis and 1Inch plugin but i have saome problems.

I am able to swap BNB to USDT without any issue but i am not able to swap USDT back to BNB even i have balance on both usdt and bnb address.

i have changed fromTokenAddress and toTokenAddress from bnb to usdt like fromTokenAddress:USDT_ADDRESS,
toTokenAddress:BNB_ADDRESS,

amount is 0.01 BNB.

but i am receiving this kind of error 74

Not enough allowance. Amount: 10000000000000000
on my wallet balance i have 28 USDT and over 200$ in BNB.

Now i am trying to swap 10 USDT for BNB but i am not able to do and i don’t know why, everything i am doing is correct. Both addresses, amont…

what i am missing please?

Not sure if that is the problem, but you could try to increase the slippage.

I tried from 1 to even 20, still the same.

I see there that it says allowance: 0, maybe it requires an approve step

yse as @cryptokid says, it needs the approve step, ERC20 token is different to native token such as BNB, you need to call the approve function from the USDT token contract in order for 1inch DEX to have access on your USDT fund to then swap it with BNB. This is because 1inch DEX is a third party, so it’s like you are giving the DEX permission to take USDT fund from your wallet and in return give you back some BNB~

1 Like

How i can call approve function from USDT token contract using 1Inch API?

Ok i found it. Yea, that was an issue, now after approval everything working perfect!
Thanks guys!

1 Like

what did you do to make it work?

First call hasAllowance function then if there is no allowance call approve function

  • hasAllowance({ chain: chain, fromTokenAddress: fromTokenAddress, amount: tokenAmount, fromAddress: user })

  • approve({ chain: chain, tokenAddress: fromTokenAddress, fromAddress: user })

1 Like

niceee :fire: the flow looks good to me :raised_hands:

1 Like