How to Tax only on selling tokens using safemoon fork

I am working on a project where we like to tax the transactions only someone sell, any idea how to achieve this. I understand that every buy sell is a swap of tokens. but is there way to find from token address from that we can figure out it is buy or sell/

if(sender == pair) //purchase

if(recipient == pair) //sale

Thanks @FreezyEx, I will give a try

This is the change I have made on the safemoon code, will it work?

    function calculateTaxFee(uint256 _amount) private view returns (uint256) {
        if(_msgSender() == uniswapV2Router.WETH()){ //buy
            return _amount.mul(_taxBuyFee).div(
        } else { // sell
            return _amount.mul(_taxSellFee()).div(

This not working for transfer from one account to another, I have no way to test the SWAP between BNB and my token in testnet for now. any suggestions?

We have msg.sender for getting sender, how to get the recipient address?

of course. Sales happens only with pancake. Transferer between holders are not sales

I don’t think so. You are using wbnb address as sender. This is wrong. The sender is the pair

If you don’t mind can you please share the code snippet to fix this?

if(recipient == pair)  { //sale

is “pair” global variable?

depends on how it is called in your contract. Usually it is named as uniswapV2Pair

The biggest challenge is to test these logics, on testnet it uses different routers than what pancakeswap, therefore the pair that is created during token is not matching with the pair created during the LP

You can just use uniswapV2Router.factory().getPair()


I’m trying to understand the logic here.

When sending tokens through pancake,

How does the transaction flow works ?

Sender → Pancake → Receiver | Pancake acting as market maker.


Sender → Receiver | Pancake acting as a broker.

Or differently ?


Did you ever get this to work? if so what coin was it?