0

I am trying to get the minimum amount of token when exchanging for pancakeswap.

My Code. I Use BNB testnet


test_provider = 'https://data-seed-prebsc-2-s3.binance.org:8545/'
w3 = Web3(Web3.HTTPProvider(test_provider))
with open('router_abi.json') as json_file:
    router_abi = json.load(json_file)
with open('factory_abi.json') as json_file:
    factory_abi = json.load(json_file)
with open("quoter_abi.json") as json_file:
    quoter_abi = json.load(json_file)
router_address = Web3.to_checksum_address("0x1b81D678ffb9C0263b24A97847620C99d213eB14")
factory_address = Web3.to_checksum_address("0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865")
quoter_address = Web3.to_checksum_address("0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2")
router_contract = w3.eth.contract(
        address=router_address, 
        abi=router_abi
        )
factory_contract = w3.eth.contract(
        address=factory_address, 
        abi=factory_abi
        )
quoter_contract = w3.eth.contract(
        address=quoter_address, 
        abi=quoter_abi
        )
public_key = ""
wallet = w3.to_checksum_address(public_key)
private_key = ""
xrp = w3.to_checksum_address("0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe")
usdt = w3.to_checksum_address("0x55d398326f99059ff775485246999027b3197955")
weth = Web3.to_checksum_address("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c")
def get_token_token_input_price(
        token0,  # input token
        token1,  # output token
        qty: int,
        fee: int,
    ) :
            sqrtPriceLimitX96 = 0
            price = quoter_contract.functions.quoteExactInputSingle(
                token0, token1, fee, qty, sqrtPriceLimitX96
            ).call()
            return price
slippage = 0.05
qty = w3.to_wei(0.03, 'gwei')
min_tokens_bought = int(
                (1 - slippage)
                * get_token_token_input_price(weth, xrp, qty , fee=3000)
            )

However, I am getting the error

***Could not identify the intended function with name `quoteExactInputSingle`, positional arguments with type(s) `address,address,int,int,int` and keyword arguments with type(s) `{}`.
Found 1 function(s) with the name `quoteExactInputSingle`: ['quoteExactInputSingle((address,address,uint256,uint24,uint160))']
Function invocation failed due to improper number of arguments.***

Help me deal with this problem I recently started learning web3. I will be very grateful for your help!

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • I wonder if the interface has changed. All the references I find show the signature as `address,address,uint24,uint256,uint160`, which is swapped from yours. The problem is that your `qty` is going to be `30,000,000`, which takes 25 bits and does not fit in a `uint24`. You might try swapping `qty` and `fee` in your call. – Tim Roberts Jun 15 '23 at 00:33

0 Answers0