Currently using IDENTICAL example from 0x starter guide.
Steps taken
deployed contract onto ropsten network
Deposited test eth to the smart contract. Then tried swapping to some ERC20's successfully:
{ ETH: '100000000000000000', WETH: '736120421643002', DAI: '296138213008071359', USDC: '6238118' }
- 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' }
- 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( q1.json.sellTokenAddress, q1.json.buyTokenAddress, q1.json.allowanceTarget, q1.json.to, q1.json.data ).send({ 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)