/quoteare designed to overlap with the raw transaction object accepted by
sendTransaction()function. What this means is that if you are using web3.js, you can directly pass the response from
/quotebecause it contains all the necessary parameters for
web3.eth.setTransaction()- from, to, value, gas, data, etc.
takerAddressfield is the address that will be performing the trade. While technically optional, we recommend providing this parameter if possible so that the API can more accurately estimate the gas required for the swap transaction. Note that this currently only works with non-contract addresses.
takerAddressattempts to swap the tokens.
eth_estimateGasresults in a revert (i.e. the swap would fail), along with reasons for the revert. In particular,
takerAddressneeds to have a sufficient balance of the
sellTokenis not ETH, the
takerAddressneeds to have approved the 0x Exchange Proxy (
0xdef1c0ded9bec7f1a1670819833240f027b25effon mainnet) to transfer their tokens. See below for an example of setting a token approval before sending the API request.
swapendpoint can be passed directly into
web3.eth.sendTransaction. Note that in a production implementation, there would be some error handling for the API response.
0xdef1c0ded9bec7f1a1670819833240f027b25eff) to transfer their DAI prior to executing the swap.
sellAmountand the gas cost of the transaction.
sellAmountin the API request parameters, we provide
buyAmount. Note that due to slippage, you may end up with slightly more than the requested
gasPricequery parameter. Just like with other quantities, values for this parameter are in wei (e.g.
9 gwei = 9 * 10^9 wei = 9000000000).
guaranteedPricereturned in the API response, the transaction will revert.
slippagePercentageparameter determines the difference between the
pricereturned in the API response and the
guaranteedPrice, i.e. the maximum acceptable slippage. It defaults to 1% but this value may not be appropriate. For example one might expect very low slippage for certain stablecoin pairs like USDC-USDT. On the other hand, one might expect (and deem acceptable) relatively high slippage for newly launched tokens with shallow liquidity.