简体   繁体   English

合约的 Web3py 交换代币路径

[英]Web3py swap tokens path of contracts

I'm trying to swap tokens with web3py using the swapExactETHForTokensSupportingFeeOnTransferTokens function, with some tokens it works perfectly, in others I get the error " execution reverted: PancakeRouter: INSUFFICIENT_OUTPUT_AMOUNT " I'm informing the parameter " amountOutMin (uint256) " to control the slippage.我正在尝试使用swapExactETHForTokensSupportingFeeOnTransferTokens function 将令牌与 web3py 交换,其中一些令牌运行良好,在其他情况下我收到错误“执行恢复:PancakeRouter: INSUFFICIENT_OUTPUT_AMOUNT ”我正在通知参数“ amountOutMin (uint256) ”来控制滑移。 that I saw differently in the tokens that work and what do not work is the path of the contracts used for the swap.我在有效和无效的代币中看到不同的是用于交换的合约的路径。

On the poocoin website when I make a trade and the contract path is " WBNB > TOKEN ", that is, from BNB direct to TOKEN, it also works using the " swapExactETHForTokensSupportingFeeOnTransferTokens " function when there is some other contract in the middle like " WBNB > WUSD > TOKEN " doesn't work, and these paths change to the same token, see images below:在 poocoin 网站上,当我进行交易时,合约路径是“ WBNB > TOKEN ”,即从 BNB 直接到 TOKEN,中间有一些其他合约,如“ WBNB > WUSD > TOKEN " 不起作用,这些路径更改为相同的令牌,请参见下图:

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

How poocoin identifies which contracts to use to swap BNB to TOKEN? poocoin 如何识别用于将 BNB 转换为 TOKEN 的合约? how to identify the contacts that I should use in the parameter " path (address[]) "如何识别我应该在参数“路径(地址[]) ”中使用的联系人

swapExactETHForTokensSupportingFeeOnTransferTokens(
                amountOutMin,
                [WBNB, ????, ???? TOKEN_BUY], # path (address[])
                sender_address,
                (int(time.time()) + 10000)

I am searching for the same thing, for now, an answer lies in this https://cryptomarketpool.com/use-web3-py-in-python-to-call-uniswap/我正在寻找同样的东西,现在,答案就在这个https://cryptomarketpool.com/use-web3-py-in-python-to-call-uniswap/

More exaclty: you locally get all listed pairs更准确:您在本地获得所有列出的对

...
allPairsLength = factory_contract.functions.allPairsLength().call()
...

then you find your route by hand.然后你手动找到你的路线。 After collecting locally all the trading pairs, you can find exactly how to get from X to Y because you have all X pairs (X/X1, X/X2... X/Xn) and all Y pairs (Y/Y1, Y/X3, ... Y/Yn).在本地收集所有交易对后,您可以找到从 X 到 Y 的确切方法,因为您拥有所有 X 对 (X/X1, X/X2...X/Xn) 和所有 Y 对 (Y/Y1, Y /X3, ... Y/Yn)。

You can get one pair, by it's id by你可以得到一对,通过它的 id by

for i in range(1, PUTTHECOUNTOFTRADINGPAIRSHERE):
    allPairs_address = factory_contract.functions.allPairs(i).call()
    contract = web3.eth.contract(address=allPairs_address, abi=pairs_abi)
    symbol = contract.functions.name().call()
    supply = contract.functions.totalSupply().call()
    print(allPairs_address, supply)

for example例如

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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