Ive been reading other results but none of them fits my situation*
I cannot resolve this issue for a while. When im running this script:
- WBNB to DOGE - Works.
- DOGE to WBNB - Fails.
What am I doing wrong?
- im registering the amountIn with (router.getAmountsOut())
- im approving the token combination with the amountIn (Token.approve())
const pair = [TOKENS.DOGE, TOKENS.WBNB]
const amountIn = ethers.utils.parseUnits(val, 'ether')
const amounts = await router.getAmountsOut(amountIn, pair);
const amountOutMin = amounts[1].sub(amounts[1].div(15))
const gasPrice = ethers.utils.parseUnits('5', 'gwei')
const gasLimit = 2000000
// Token = Token(TOKENS.DOGE)
await Token.approve( pancakeRouter, amountIn, { gasLimit, gasPrice } )
const buyTx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
pair,
wallet.address,
Math.floor(Date.now() / 1000) + 60 * 10,
{ gasLimit, gasPrice }
)
Error:
reason: 'transaction failed',
code: 'CALL_EXCEPTION',
transactionHash: '0xabd9862116711eacaa109d4a832c87e947af666745186b51cce7fe864a310c96',