beeb / pancaketrade

Limit orders for PancakeSwap
GNU General Public License v3.0
200 stars 92 forks source link

Error when using sell_token method from Network class #31

Closed emelyanko closed 2 years ago

emelyanko commented 2 years ago

I can't sell tokens using Network.sell_tokens (error 'web3.exceptions.ContractLogicError: execution reverted: TransferHelper: TRANSFER_FROM_FAILED'). Buying tokens is successful.

beeb commented 2 years ago

Does it happen also when using the bot through telegram?

This message would normally indicate that the transfer function of the token contract failed to execute properly. The reason can be a lot of things, it really depends on the token.

For example, it could be a scam contract (so-called "honeypot") where selling is prohibited to make the chart look green.

If you share more information about the token and the value of parameters you passed to the sell_tokens function, I can look into it. It's probably not a bug with pancaketrade so I'm gonna close this issue but we can continue to discuss it here.

emelyanko commented 2 years ago

Происходит ли это также при использовании бота через Telegram?

I haven't used Telegram yet. I sell Cake("0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82")

My parameters:

    net.sell_tokens(
        token_address=token_address),  # Cake ChecksumAddress
        amount_tokens=Wei(amount),  # 100,000,000,000,000,000 Wei
        slippage_percent=Decimal('2'),  # 2.0 Decimal
        gas_price=None  # or '+10.1',
    )

I've changed the gas, slippage, amount parameters a lot. I used other tokens and checked their honeypot

I think the message appears when this block is accessed:

gas_limit = Wei(
            int(
                Decimal(func.estimateGas({"from": self.wallet, "value": Wei(0)}))
                * Decimal(1.2)
            )
        )
beeb commented 2 years ago

I think it's because you did not approve the PancakeSwap Router v2 contract to spend your CAKE tokens. You need to call Network.approve(token_address) (which will make a transaction) before selling any token. You can check if the token was already approved by calling Network.is_approved(token_address) which makes a free call (no transaction).

If that's not the problem, then please check the following: How did you instantiate the Network class? Are you passing the right parameter for the wallet argument in the constructor ? Do you have 0.1 CAKE = 100,000,000,000,000,000 Wei in this wallet?

emelyanko commented 2 years ago

Network.approve(token_address) -> WORKING ! )) THANK YOU SO MUCH !!!