SwapAndLiquify function transferred all my BNB from PancakeSwap to the contract address

I recently set swapandliquify to true and when I tested a transaction after this, all of my liquidity 1.93 BNB from pancakeswap was transferred to my contract address. Is there a way to get this back? Here is the transaction where it occurred https://bscscan.com/tx/0xb56cb68ea096906d4281912f986ea68a72c0a0b8a56e0ce67c0b0ea2c2cc5ffc

Here is my contract address: https://bscscan.com/address/0xdba9b1d91e710b4ac9a1df3a7b3f632f4297f0a3
Any assistance is greatly appreciated, thank you

Tell friend, ok?

Hey friend, for this you need to create a function to remove the bnb from the contract! As you did not write I believe that it is not possible to remove…

Even this is Safemoon’s auditing problem.

create a Whitdraw function.
`` `

function sendContractBalance (address payable to) public onlyOwner {
       require (address (this) .balance> 0, "07");
       to.transfer (address (this) .balance);

`` `
** Remembering that you need to deactivate the exchange and liquefy and approve the removal of the bnb from the contract and then write the contract to send the bnb balance to your address **


Any idea why the swapandliquify would do the functionality that it did? Weird it moved all the BNB from pancakeswap LP to the contract address

The SwapandLiquify function does just that! Take half of the tokens and convert them to bnb and send them to the contract.

Analyzing your contract, I saw that it is enabled, you should have selected false, go to write contract and select SwapandLiquify and leave as false.

Another big problem I found in your contract is that you don’t have any function to withdraw tokens, not even withdrawETH(bnb).

1 Like

Is there anyway for the liquidity to be added back to the pancake swap liquidity pool?

From the contract address

Try this! I don’t know if you’ll make it but it’s hard to try…

  1. Go to write contract, and connect with the wallet that owns the contract.
  2. Approve a contract token transfer.

Spender: You put the address you are going to send, try putting the address of the wallet that owns the contract.
Amount: put 1 to see if it goes all bnb.

3)Go to transfer from,

Sender: Here you enter the address of your contract.
Recipient: Here you enter the address you approved in the case the wallet that owns the contract.
Amount: 1

Try to do this, if not, repeat the same process for the Transfer function above.

If you can’t let me know.

1 Like

Hi Skynance, thank you for your continued help. It looks like it’s trying to transfer BEP20 token perhaps. Here is the transaction. https://bscscan.com/tx/0xf8f95adeb152150410470f154f0c2e69aefe744dc56fcd8983d5bdacfeb7f08c

The dev who wrote the contract sent this, not sure if this helps:

I don’t understand what he means by decreasing the number of tokens before the exchange and then selling tokens for swap…

Try to understand this part! I understand that I have to enable swapforliquify again.

1 Like

It seems like @skynance really do a lot, really thanks!

Emmmm, I am not sure, but I think if you set swapAndLiquifyEnabled as false, maybe your token will lose the original intention, but it all depend on you.

Maybe you can add some more tokens( DAPCAT) to this contract, and then when you swap on the pancake, it will consume some BNB, but I do not think this can fundamentally solve your problem, actually, when you add liquidity by swapping on the pancake, in most cases, either token is left, or BNB is left.

Shortly, the current situation just fits with your contract design, and you do not have a function to withdraw BNB directly.

Kind reminder, you should have a test on the testnet before launching on the mainnet, this will decrease bugs.