0

I'm using 0x swap quote api to convert my WETH -> UNI token. 0x swap quote gives "gas estimation failed error" on ropsten testnet even though I have enough funds.

The 0x swap price gives the gas estimation as 111000 wei and I have around 1.5 ropstenETH. So I don't understand why this error shows up. Isn't the gas estimate by 0x swap price api accurate enough? How much ropstenETH should I aim to have for this to work?

Attaching the code for reference:

const params = {
    sellToken: currentTrade.from.address,
    buyToken: currentTrade.to.address,
    sellAmount: amount,
    takerAddress: account,
  };

  // Fetch the swap quote.
  const response = await fetch(
    `https://ropsten.api.0x.org/swap/v1/quote?${qs.stringify(params)}`
  );

Any help is appreciated. Thank you.

1 Answer 1

0

TL;DR: Try this solution

From the code, I presume you're running the Road To Web3 Code example.

This error usually happens if takerAddress does not have the funds that are intended to be traded or allowances set up to make the trade.

A couple things to check:

  • Have you updated the CoinGecko List to pull Ropsten tokens (the default is Mainnet tokens)? If not updated, the quote will be using incorrect addresses and expecting that the account has different tokens
  • Can you double-check that the takeraddress does have the token to be traded (WETH)? WETH and RopstenETH are two different tokens; ETH does not conform to the ERC-20 standard (https://weth.io/).
  • Check that the token allowance for WETH set properly

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.