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

**URL:** https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618
**Category:** Contracts
**Tags:** bep20
**Created:** [July 16, 2021, 8:36pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618 "2021-07-16T20:36:03Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![dappercats](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dappercats](https://forum.openzeppelin.com/u/dappercats)
#### Post date: [July 16, 2021, 8:36pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/1 "2021-07-16T20:36:03Z")

</div>

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](https://bscscan.com/tx/0xb56cb68ea096906d4281912f986ea68a72c0a0b8a56e0ce67c0b0ea2c2cc5ffc)

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

---

<div class="post-metadata">

### Author: ![skynance](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skynance/32/8420_2.png) [@skynance](https://forum.openzeppelin.com/u/skynance)
#### Post date: [July 16, 2021, 11:01pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/2 "2021-07-16T23:01:51Z")

</div>

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.  
`` `

```auto
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 \*\*

---

<div class="post-metadata">

### Author: ![dappercats](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dappercats](https://forum.openzeppelin.com/u/dappercats)
#### Post date: [July 17, 2021, 12:02am UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/3 "2021-07-17T00:02:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![skynance](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skynance/32/8420_2.png) [@skynance](https://forum.openzeppelin.com/u/skynance)
#### Post date: [July 18, 2021, 1:24pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/4 "2021-07-18T13:24:59Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![dappercats](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dappercats](https://forum.openzeppelin.com/u/dappercats)
#### Post date: [July 18, 2021, 11:37pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/5 "2021-07-18T23:37:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dappercats](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dappercats](https://forum.openzeppelin.com/u/dappercats)
#### Post date: [July 18, 2021, 11:37pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/6 "2021-07-18T23:37:55Z")

</div>

From the contract address

---

<div class="post-metadata">

### Author: ![skynance](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skynance/32/8420_2.png) [@skynance](https://forum.openzeppelin.com/u/skynance)
#### Post date: [July 19, 2021, 3:55am UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/7 "2021-07-19T03:55:14Z")

</div>

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.

 ![1](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/5/511722ae3616e367ad7e06c5ba0ab55f20a80571.png)  
**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,  
 ![1](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/b/b2c2014662aadebd1baf6192cbe48463b325fae8.png)

**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.

---

<div class="post-metadata">

### Author: ![dappercats](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dappercats](https://forum.openzeppelin.com/u/dappercats)
#### Post date: [July 19, 2021, 5:14pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/8 "2021-07-19T17:14:33Z")

</div>

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](https://bscscan.com/tx/0xf8f95adeb152150410470f154f0c2e69aefe744dc56fcd8983d5bdacfeb7f08c)

The dev who wrote the contract sent this, not sure if this helps:  
 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/2/2edf33a247370e80f30a6c41ceccaa0226512868.jpeg)

---

<div class="post-metadata">

### Author: ![skynance](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skynance/32/8420_2.png) [@skynance](https://forum.openzeppelin.com/u/skynance)
#### Post date: [July 19, 2021, 6:44pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/9 "2021-07-19T18:44:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)
#### Post date: [July 20, 2021, 2:17am UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/10 "2021-07-20T02:17:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Extinctionist30](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Extinctionist30](https://forum.openzeppelin.com/u/Extinctionist30)
#### Post date: [December 7, 2021, 10:54pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/11 "2021-12-07T22:54:16Z")

</div>

Hey Skynance. Hope you are well!

I needed a bit of help. I'm launching a token and I've modified a pre existing contract.

Old contract code link: [https://bscscan.com/address/0xbddfe03f24c09505fb2db5f9df1589dab17ddaae#code](https://bscscan.com/address/0xbddfe03f24c09505fb2db5f9df1589dab17ddaae#code)

The contract collects a percentage of tax (6% Liquidity) and then swaps the tokens to bnb and sends them to the marketing wallet and airdrop wallet. Earlier the marketing divisor was 3 and airdrop divisor was 3. And it would Swap the tokens to bnb and then send the bnb in equal parts to the two wallets mentioned above

I then changed the liquidity fee to 8%. And the marketing divisor to 5 and airdrop divisor to 3. While testing the contract on testnet. It doesn't seem to be swapping the tokens collected in the contract to bnb.

New modified contract code (testnet) link: [https://testnet.bscscan.com/address/0xcc788bcdb899ef2b11f92ec7315a41e9024c0242#code](https://testnet.bscscan.com/address/0xcc788bcdb899ef2b11f92ec7315a41e9024c0242#code)

The minimum token to swap is set to 100 million and the contract has collected 1.1 billion

Any idea why it's not swapping to bnb?

---

<div class="post-metadata">

### Author: ![Crypto\_Pumps](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/crypto_pumps/32/11681_2.png) [@Crypto\_Pumps](https://forum.openzeppelin.com/u/Crypto_Pumps)
#### Post date: [February 7, 2022, 7:53pm UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/13 "2022-02-07T19:53:50Z")

</div>

Where do you change `swapAndLiquifyEnabled` function to false??

---

<div class="post-metadata">

### Author: ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)
#### Post date: [February 8, 2022, 12:37am UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/14 "2022-02-08T00:37:43Z")

</div>

Hi, welcome! 👋

In `dappercats`'s contract that showed above, he can call this function to set:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/1/10b54dac246266256a8ecba77de3bea5bd1db94a.png)

---

<div class="post-metadata">

### Author: ![Azhar\_Ali\_Shar](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/azhar_ali_shar/32/18219_2.png) [@Azhar\_Ali\_Shar](https://forum.openzeppelin.com/u/Azhar_Ali_Shar)
#### Post date: [May 8, 2023, 8:27am UTC](https://forum.openzeppelin.com/t/swapandliquify-function-transferred-all-my-bnb-from-pancakeswap-to-the-contract-address/12618/15 "2023-05-08T08:27:50Z")

</div>

sorry to jump in. But i need some help bro.  
I have a just created a token on BSC and when I try to add liquidity using pancakeswap i get this error.  
""Add liquidity failed: The input token cannot be transferred. There may be an issue with the input token. (TransferHelper: TRANSFER\_FROM\_FAILED)

for info:  
Contract address: 0x6E4Cf2341698F6a8Be1192dF2A6793c0d7E4f7FE
