Currently using IDENTICAL example from 0x starter guide.

Steps taken

  1. deployed contract onto ropsten network

  2. Deposited test eth to the smart contract. Then tried swapping to some ERC20's successfully:

{ ETH: '100000000000000000', WETH: '736120421643002', DAI: '296138213008071359', USDC: '6238118' }

  1. Made sure allowance (owner = smart contract, spender = 0x allowanceTarget) for ERC20s were set to some high number

{ ETH: '0', WETH:
'115792089237316195423570985008687907853269984665640564039457584007913129639935', DAI:
'115792089237316195423570985008687907853269984665640564039454010447295162926691', USDC:
'115792089237316195423570985008687907853269984665640564039457584007913115620207' }

  1. tried swapping DAI for ETH via contract using swap-contract.js example from 0x.
const swap = {
    "sellTokenAddress" : "0xad6d458402f60fd3bd25163575031acdce07538d", 
    "buyTokenAddress"   :"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
    "sellAmount": 10000000000000000

const API_QUOTE_URL=`https://ropsten.api.0x.org/swap/v1/quote`;

const qs = createQueryString({
    "sellToken" : swap['sellTokenAddress'].toLowerCase(),
    "buyToken"  : swap['buyTokenAddress'].toLowerCase(),
    "sellAmount": swap['sellAmount'],
    "slippagePercentage" : 0.01

const response = await fetch(`${API_QUOTE_URL}?${qs}`);
const q1= {"json" : await response.json()};

const receipt = await contract.methods.fillQuote(
    from: account.address,
    value: q1.json.value,
    gasPrice: q1.json.gasPrice,
    gas: 500000

I tried few times but Im getting transaction revert w/o any clear message: here and here

Where am I going wrong? (there's enough DAI in the smart contract, and with DAI allowance for 0x allowanceTarget set to max - 0xfff...ff)

1 Answer 1


As far as I can see, the SimpleTokenSwap.fillQuote function only supports trading ERC20 tokens, try using WETH as the buyToken instead of ETH.

For reference, ETH does not have a balanceOf function which the fillQuote tries to call here, this is probably causing it to fail

  • Thanks! Ah, yes.. didn't realize eth and erc20 had different ways of checking balance. But for some reason, DAI is giving a bit of headache: ethereum.stackexchange.com/questions/123180/…
    – TaeWoo
    Commented Mar 6, 2022 at 5:35
  • Any idea what this error is? I'm using the same code, except I'm submitting the tx by multiplying quoted gas by 3 using quote where I don't specify takerAddress. ``` Error: overflow (fault="overflow", operation="toNumber", value="285837258167192856142155196896925256079494159121", code=NUMERIC_FAULT, version=bignumber/5.5.0) ``` This happens randomly.
    – TaeWoo
    Commented Mar 24, 2022 at 13:35

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.