# I want 2% of transactions to go to the charity wallet

**URL:** <https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067>\
**Category:** Contracts\
**Tags:** erc20, bep20\
**Created:** [June 7, 2021, 10:58am UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067 "2021-06-07T10:58:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chriscarp87](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@chriscarp87](https://forum.openzeppelin.com/u/chriscarp87)\
**Post date:** [June 7, 2021, 10:58am UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/1 "2021-06-07T10:58:27Z")

</div>

Hi I am new to all of this. I have started a new coin on BSC chain and I want 2% of transactions to go to the charity wallet. Is there any way I could do that simply? Thanks in advance for any help

> **[Contract Address 0xbf00279c974491503a7b87d50246031e019ede9d | BscScan](https://bscscan.com/address/0xbf00279c974491503a7b87d50246031e019ede9d#code)**
>
> The Contract Address 0xbf00279c974491503a7b87d50246031e019ede9d page allows users to view the source code, transactions, balances, and analytics for the contract address. Users can also interact and make transactions to the contract directly on...

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [June 7, 2021, 11:42am UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/2 "2021-06-07T11:42:24Z")

</div>

Check YUMMY token on BSCscan or MUNCH on etherescan

---

<div class="post-metadata">

**Author:** ![chriscarp87](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@chriscarp87](https://forum.openzeppelin.com/u/chriscarp87)\
**Post date:** [June 7, 2021, 8:22pm UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/3 "2021-06-07T20:22:29Z")

</div>

I am looking at the YUMMY contract. It seems what they are doing is swap and liquify. Does that mean half of the liquidity pool tax goes to the charity wallet as BNB? And if I just paste the following lines of code, do you think it would work for my coin?

function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {  
// split the contract balance into thirds  
uint256 halfOfLiquify = contractTokenBalance.div(4);  
uint256 otherHalfOfLiquify = contractTokenBalance.div(4);  
uint256 portionForFees = contractTokenBalance.sub(halfOfLiquify).sub(otherHalfOfLiquify);

```
    // capture the contract's current ETH balance.
    // this is so that we can capture exactly the amount of ETH that the
    // swap creates, and not make the liquidity event include any ETH that
    // has been manually sent to the contract
    uint256 initialBalance = address(this).balance;

    // swap tokens for ETH
    swapTokensForEth(halfOfLiquify); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered

    // how much ETH did we just swap into?
    uint256 newBalance = address(this).balance.sub(initialBalance);

    // add liquidity to uniswap
    addLiquidity(otherHalfOfLiquify, newBalance);
    sendBNBToCharity(portionForFees);
    
    emit SwapAndLiquify(halfOfLiquify, newBalance, otherHalfOfLiquify);
}

function swapTokensForEth(uint256 tokenAmount) private {
    // generate the uniswap pair path of token -> weth
    address[] memory path = new address[](2);
    path[0] = address(this);
    path[1] = uniswapV2Router.WETH();

    _approve(address(this), address(uniswapV2Router), tokenAmount);

    // make the swap
    uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
        tokenAmount,
        0, // accept any amount of ETH
        path,
        address(this),
        block.timestamp
    );
}
```

---

<div class="post-metadata">

**Author:** ![AlternativePractical](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alternativepractical/32/7429_2.png) [@AlternativePractical](https://forum.openzeppelin.com/u/AlternativePractical)\
**Post date:** [July 8, 2021, 1:03pm UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/4 "2021-07-08T13:03:28Z")

</div>

Hey,  
I have tried to fork yummy on both the testnet, and the mainnet. However, I can see the tokens that are being collected for the charity wallet accumulate in the balance of my contract, but after the threshold of: uint256 private numTokensSellToAddToLiquidity = 300000000 \* 10 **1 \* 10** 9;  
has been reached, the tokens are not swapped for BNB and remain in the contract instead of being sent to the charity wallet.

Do you have any idea how to solve this issue?

Also, Im not sure if tokens are automatically added to the liquidity pool. I do see the balance of the tokenholders change after I trade in the test router and V2 router of pancakeswap.

Cheers1

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [July 8, 2021, 5:31pm UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/5 "2021-07-08T17:31:25Z")

</div>

it is normal. That number represents the amount to swap for BNB to send to liquidity and marketing

---

<div class="post-metadata">

**Author:** ![AlternativePractical](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alternativepractical/32/7429_2.png) [@AlternativePractical](https://forum.openzeppelin.com/u/AlternativePractical)\
**Post date:** [July 9, 2021, 11:02am UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/6 "2021-07-09T11:02:45Z")

</div>

Yes, but the tokens arent swapped for BNB when I deploy an exact copy of yummy coin. If I call the amount of tokens stored in the contract it keeps going up when transacting, instead of being liquified after the threshold is reached

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [July 9, 2021, 11:07am UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/7 "2021-07-09T11:07:58Z")

</div>

did you enabled swapandliquify?

---

<div class="post-metadata">

**Author:** ![AlternativePractical](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alternativepractical/32/7429_2.png) [@AlternativePractical](https://forum.openzeppelin.com/u/AlternativePractical)\
**Post date:** [July 9, 2021, 11:19am UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/8 "2021-07-09T11:19:54Z")

</div>

swapandliquifies, default setting is true (which I thought was required) so I didnt do anything with it

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

---

<div class="post-metadata">

**Author:** ![AlternativePractical](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alternativepractical/32/7429_2.png) [@AlternativePractical](https://forum.openzeppelin.com/u/AlternativePractical)\
**Post date:** [July 9, 2021, 12:02pm UTC](https://forum.openzeppelin.com/t/i-want-2-of-transactions-to-go-to-the-charity-wallet/10067/9 "2021-07-09T12:02:00Z")

</div>

I solved it! the default option is enabled, however I needed to turn it off and then turn it on again so now it works. Thanks for your clue!
