1msc.xyz

How to simulate buy and sell tax on a token before trading

You see a token that looks promising. You check the contract, the liquidity, the ownership renouncement. One risk remains hidden: transaction taxes. A token can take a cut every time someone buys or sells, and that cut might be 5%, 10%, or even higher. You can test this yourself before you trade.

The method works on any DEX that uses a Uniswap V2-style router. PancakeSwap and Uniswap itself both qualify. The trick is to use the Read Contract tab on the router, not on the token. You call a function named getAmountsOut, which reveals what the DEX would give you for a trade, minus any fees the DEX charges. The difference between that number and what a simple reserve ratio predicts is the tax.

Before you start

You need two things: the token contract address and the router contract address for the DEX you plan to use. For Solana, you would use the Raydium router; for Ethereum or BNB Chain, you use the PancakeSwap or Uniswap V2 router. A block explorer like Etherscan or Solscan lets you interact with the router's contract.

Open the router contract on the block explorer. Find the Contract tab, then the Read Contract sub-tab. You will see a list of callable functions. Find getAmountsOut.

Simulating a buy

A buy on a DEX means swapping the base pair token - usually WETH, WBNB, or USDC - into the token you want to test. You need to call getAmountsOut with two parameters: the input amount and an array of token addresses.

The input amount should be meaningful. Use a value that a real buyer might trade, say 0.1 ETH or 10 USDC. You must express this in the smallest unit of the input token: ETH has 18 decimals, so 0.1 ETH becomes 100000000000000000, while USDC has 6 decimals, so 10 USDC becomes 10000000.

The array is ordered: [input token address, output token address]. For a buy, the input is the base pair token, the output is your test token.

Click Query. The function returns an array of amounts; the last element is how much of your test token you would receive.

Now compute the expected output with no tax. Look at the DEX pool for your token - you need the reserves of the base token and the test token, and DexScreener shows these. The expected output without tax is: (input_amount * reserve_of_test_token) / (reserve_of_base_token + input_amount). Use the same reserve numbers and the same input amount.

Subtract the actual output from the expected output, divide that difference by the expected output, and multiply by 100. That number is the buy tax percentage.

Example: Expected output is 1000 tokens, actual output is 950, difference is 50. 50 / 1000 = 0.05. That is 5% buy tax.

Simulating a sell

A sell is the reverse swap: you send your test token in and get the base token out. The getAmountsOut call uses the same function but reversed addresses.

The input amount is now an amount of your test token - use a realistic amount. The array is [test token address, base token address]. The returned last element is the base token you would receive.

The expected output with no tax works the same formula, but reversed: (input_amount_of_test * reserve_of_base) / (reserve_of_test + input_amount_of_test). Compare actual to expected as before. The difference is the sell tax.

What to watch for

Some tokens have a buy tax but no sell tax. Some have the opposite. A few tax both directions. A tax above 10% is aggressive; a tax above 20% is a trap for anyone who tries to exit.

The simulation only works if the router contract is verified and getAmountsOut is public. Most major DEX routers meet this condition. If the token has a custom router, the method may not apply.

The numbers you get are as of the moment you query. Reserve ratios shift with every trade, so check again before you commit real funds. A token that was 5% tax an hour ago could be 10% now if someone altered the pool, although that is rare.

This test complements the other checks you should already be doing. No single method catches everything. The combination of contract verification, liquidity lock checks, and tax simulation gives you a clearer picture. Trade carefully.

Not financial advice. 1msc.xyz publishes market data and general information about digital assets. Crypto assets are volatile and you can lose everything you put in. Nothing here is a recommendation to buy, sell or hold, and we make no price predictions.

Prices are sourced from third parties and may be delayed or wrong. Verify anything you intend to act on against a primary source.

Back to token safety