简体   繁体   中英

Web3: How to get the maxTransactionAmount for a token in python?

Im currently working on code where i want to be able to buy what is max allowed to buy for the specific token.

In the smart contract, they sometimes implements a max transaction, ie: 1% Max buy. How can my code detect it in a smart contract and use it as a buy parameter in the function contract.functions.swapExactETHForTokens( )? i imagine it would be something like,

maxTokens = token_contract.functions.maxAllowedTransactions

then, i can use maxTokens as a parameter in the swapExactETH.. function. I have tried googling around but i havent encountered anything similar.

Thanks!

I assume you are talking about uniswap v3/v2. There is no "max amount". The percentage you are referring to is the slippage amount which is represented as the variable amountOutMin in the swapExactETHForTokens function. This parameter is the minimum amount that you are willing to receive for x amount of ETH.

If you don't care about slippage then you can set amountOutMin to be equal to 0. You will likely get frontrun by MEV bots if you do this though.

The true maximum amount of a token that you can buy is the total amount of the tokens in the pool that you are swapping in. If a pool has 50 Buttcoins and 30 Dog coins, then you can buy a maximum of 30 dog coins for an infinite amount of Buttcoins. Based on the swap formula of:

buttcoin amount = 50 Butt / (30 Dog - 30 Dog) = infinity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM