I am trying to simulate a market moving tx on BSC
I am getting the following error: revert Pancake: TRANSFER_FAILED

Does anyone know why, I have approved the router to spend the token on my behalf, furthermore I set slippage to 0🤔



let marketMove = async () => {

try {

const Router = await new web3.eth.Contract(PCABI, PCaddress);
const ERC20 = await new web3.eth.Contract(ERCABI, pair_token);
const WBNB = await new web3.eth.Contract(ERCABI, wbnb);

let token_balance = await ERC20.methods.balanceOf(address).call()
console.log(token_balance)
await ERC20.methods.approve(PCaddress, token_balance).send({ from: address })
await WBNB.methods.approve(PCaddress, token_balance).send({ from: address })

let sellPath = [pair_token, wbnb]
const myContract = await new web3.eth.Contract(deployed_Contract.abi, l_address)
let ratio = await myContract.methods.getAmountOutMin(pair_token, wbnb, token_balance).call()
console.log(ratio)
await Router.methods.swapExactTokensForTokens(token_balance, 0, sellPath, address, Date.now() + 60).send({ from: address, gasPrice: web3.utils.toWei("10", "Gwei") })


} catch (err) {
console.log("error inside the stoploss " + err)
}

}

marketMove()

Sep 18, 2021, 1:40 PM
Thanks for your help, maybe this code snippet if it works also saves other people some time who want to the same, also I know it is unnecessary to approve the router to spend WBNB for me, but I am desperate
Sep 18, 2021, 1:43 PM
why you use swapExactTokensForTokens? use swapExactTokensForETH / swapExactTokensForETHSupportingFeeOnTransferTokens
Sep 18, 2021, 2:26 PM
Great man let me try
you made a good point there, I think the token I am swapping may tax you on trading, however I unfortunately get the same error
Sep 18, 2021, 2:40 PM
mhm.. it should work even with a 100% fee as you accept 0 tokens. There is something wrong with the erc20 you're trying to swap
double-check it's transfer function
learned it the hard way on mainnet 😂
Sep 18, 2021, 2:43 PM
you are cool guys, thanks for helping I should debug it on tenderly probably, but first I am going to try a different token
Sep 18, 2021, 2:45 PM
yeah, tenderly + testnet may save you alot of time o/
Sep 18, 2021, 2:46 PM
What is tenderly?
Sep 18, 2021, 2:55 PM
https://tenderly.co/
Sep 18, 2021, 2:58 PM
Tenderly is great
you can simulate txes
in my case just found out about this revert reason
but this came up cause I was stupid lol😂 had to change the address tenderly sends from zero address by default
Sep 18, 2021, 3:08 PM

© 2024 Draquery.com All rights reserved.