0

I am working with the Quoter from Uniswap V3, here is the part of the function that challenges me:

...

// Reformat Amount In
  if (!isNaN(amtIn)) {amtIn = amtIn.toString()}
  let amountIn = ethers.utils.parseUnits(amtIn, inputDecimalsA).toString()

  // Get Uniswap V3 Quote
  const quoterAddress = "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6";
  const quoterContract = new ethers.Contract(quoterAddress, QuoterABI, provider)
  let quotedAmountOut = 0
  try {
    quotedAmountOut = await quoterContract.callStatic.quoteExactInputSingle(
      inputTokenA,
      inputTokenB,
      tokenFee,
      amountIn,
      0)
  } catch (err) {
    console.log("Something went wrong....", err)
    return 0
  }

    // Format Output
    let outputAmount = ethers.utils.formatUnits(quotedAmountOut, inputDecimalsB).toString()
    return outputAmount
}

When I run this with the latest version of uniswap sdk and ethers, I get these errors:

TypeError: Cannot read properties of undefined (reading 'quoteExactInputSingle')

or

contract runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.7.1)

It seems like the latest dependencies having a problem with the .callStatic but even without it it didn't work.

The interesting thing is, when I am using older dependency versions like below, it works. Older Versions:

"dependencies": {
    "@uniswap/sdk-core": "^3.0.1",
    "@uniswap/v3-sdk": "^3.6.3",
    "dotenv": "^16.3.1",
    "ethers": "^5.7.2",
    "uniswap": "^0.0.1",
    "web3": "^1.6.1",
    "yarn": "^1.22.19"
  }

I tried to read the Quoter.sol Smart Contract and try to understand what causes the problem, but without success. Link: (https://github.com/Uniswap/v3-periphery/blob/v1.0.0/contracts/lens/Quoter.sol)

I would really appreciate if someone out there could help me solving this issue and tell me what to change in the code to make it work with the latest dependencies since I fear that other functions I would like to use like trades are not going to work with the old versions. Thanks in advance

1 Answer 1

0

Pls go ahead and follow this example:

https://github.com/Uniswap/examples/blob/main/v3-sdk/quoting/src/libs/quote.ts

if you followed, try using: quoterContract.connect(signer).callStatic.quoteExactInputSingle(...)

try to get siger from etherjs

Updated

const signer = new ethers.Wallet(your_private_key_string, provider);

pass the signer instead of provider.

Pls, vote up if it solved your problem, otherwise leave a comment :)

2
  • Well if I do this with const provider = new ethers.JsonRpcProvider("xxx"); as provider and try to get a signer like this signer = await provider.getSigner() it throws me the following error: throw new Error("no such account");. Thank you for trying to help me:) Sep 21, 2023 at 15:03
  • @Christopherus I've updated the answer. that is because you didn't pass your account(private-key) to the provider object. so how the provider can understand which account you're talking to.
    – 0xbeny
    Sep 22, 2023 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.