0

After fetching the Quote I get this error:

Quote:
Object code: 105 reason: "SenderNotAuthorizedError" values: {sender: '0xdef1c0ded9bec7f1a1670819833240f027b25eff'}

My code is:

const BigNumber = require('bignumber.js');

const qs = require('qs');

const Web3 = require('web3');


let currentTrade = {};

let currentSelectSide;

let tokens;

...




async function getQuote(account) {
    console.log("Getting Quote");

    if (!currentTrade.from || !currentTrade.to || !document.getElementById("from_amount").value) return;
    let amount = Number(document.getElementById("from_amount").value * 10 ** currentTrade.from.decimals);

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

    // Fetch the swap quote.
    const response = await fetch(`https://api.0x.org/swap/v1/quote?${qs.stringify(params)}`);
    swapQuote = await response.json();
    console.log("Quote: ", swapQuote);

    document.getElementById("to_amount").value = swapQuote.buyAmount / (10 ** currentTrade.to.decimals);
    document.getElementById("gas_estimate").innerHTML = swapQuote.estimatedGas;

    return swapQuote;
}

1 Answer 1

0

If the takerAddress is included in the quote fetch, you must first confirm two things:

  1. That the taker has a sufficient amount to sell.
  2. The taker has approved or allowed the Zero Ex Exchange Proxy to spend the sellToken on their behalf.

Also confirm that the token allowance for the 0x Exchange Proxy is greater than the sellAmount entered.

I believe this error is resulting from the takerAddress having not yet approving a token allowance for the appropriate ZeroEx Exchange Proxy Contract Address.

https://docs.0x.org/0x-api-swap/advanced-topics/how-to-set-your-token-allowances

Hope that helps!

Your Answer

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

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