How do I find the tax of a token programatically?
Asked Answered
H

2

9

I'm trying to fetch the Buy or Sell Tax of a BSC token, but I haven't found a way yet. I query the DEX via router_contract.functions.getAmountsOut(web3.toWei(1, 'Ether'), [ buying_token_address, pair_token]).call() (in this case pancakeswap), but this value I believe it doesn't include token tax.

Does anyone know how I can calculate the tax?

Harden answered 16/1, 2022 at 19:41 Comment(0)
T
1

I am the co-founder of Trading Strategy. We have recently published a new feature that shows any "token tax" or hidden transfer fees on Uniswap, Pancake swap and other Uniswap v2 like exchanges. A lot of tokens with exotic tokenomics have these and it is often hard to find detailed information on this because it's not part of any token standard. This should make trading safer, as you can see if a trading pair has any "hidden fees" included. We also display a warning regarding any potential honeypot (buy only) tokens.

enter image description here

This should make trading much safer on DEXes.

The token tax data is available through free real-time and dataset download APIs. You can read more about the feature and how to use it in our blog post.

Trephine answered 21/5, 2022 at 9:15 Comment(1)
Hi, I have followed the link and found that you're offering API for token taxes, but the mentioned link, for that API documentation, wasn't working tradingstrategy.ai/docs/programming/token-tax.htmlChartres
S
0

If you're using JavaScript, it's possible to use the web3.eth.call function from the web3.js module.

From the web3.js docs: (view here)

Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

You'll be able to find out the result of the transaction, without actually executing it. You can therefore calculate how many tokens were taken from the contract in the transaction, and calculate the tax.

Sacculate answered 7/4, 2022 at 12:46 Comment(2)
I'm trying to test this approach with ethers. I'm doing this const result = await contract.callStatic.transfer(recipient.address, transferAmount) console.log(result) but result only returns true without more details, is there another way to do this ?Clyde
"If you're using JavaScript" OP is using Python as indicated by the web3py tag they included.Gaga

© 2022 - 2024 — McMap. All rights reserved.