DEX tutorial issue with swapping: Error: [object Object]

Hi All,

I cloned the dex tutorial from github, I get the following error message when I execute the swap.

So it comes after enter the tokens, the price and gas fees are display. The execution doesn’t work.

Any ideas?

Thanks!

POST https://k15kzgmv9jic.usemoralis.com:2053/server/functions/oneInch_swap 400
dispatch @ moralis.js:26280
ajax @ moralis.js:26287
(anonymous) @ moralis.js:26394
Promise.then (async)
request @ moralis.js:26388
run @ moralis.js:458
run @ moralis.js:384
(anonymous) @ moralis.js:6615
tryCatch @ moralis.js:74788
invoke @ moralis.js:75019
(anonymous) @ moralis.js:74844
asyncGeneratorStep @ moralis.js:30969
_next @ moralis.js:30991
(anonymous) @ moralis.js:30998
Wrapper @ moralis.js:57965
(anonymous) @ moralis.js:30987
(anonymous) @ moralis.js:6659
doSwap @ main.js:125
trySwap @ main.js:117
main.js:120 Error: [object Object]
at handleError (moralis.js:26416:17)

try to look in network tab on the payload and on the response for that request

not sure where I have to look at. Not that much experience yet. this?:

  1. _ClientVersion: “js1.8.1”
  2. _InstallationId: “”

In the browser, in network tab, similar to how you look in console tab in browser, next to console tab there is a network tab

yes, I found that one, thanks. But what do I need to do? What should I look for?

you can look on how the requests look like there, see what it was sending and what it was receiving for that specific request, it should be a better error message there and you can validate the sent payload data if it looks to be as expected

You can also add more details of which token you’re swapping from and which token you’re swapping to and it’s network, and also if you got enough balance for the token you’re swapping from.

Looks like Error: [object object] is from an alert, if so, you can change the alert to console to get more info about the error

thanks! I see the following: first this one, which is not the main problem I think:
POST https://k15kzgmv9jic.usemoralis.com:2053/server/functions/oneInch_swap 400
dispatch @ moralis.js:26280
ajax @ moralis.js:26287
(anonymous) @ moralis.js:26394
Promise.then (async)
request @ moralis.js:26388
run @ moralis.js:458
run @ moralis.js:384
(anonymous) @ moralis.js:6615
tryCatch @ moralis.js:74788
invoke @ moralis.js:75019
(anonymous) @ moralis.js:74844
asyncGeneratorStep @ moralis.js:30969
_next @ moralis.js:30991
(anonymous) @ moralis.js:30998
Wrapper @ moralis.js:57965
(anonymous) @ moralis.js:30987
(anonymous) @ moralis.js:6659
doSwap @ main.js:125
trySwap @ main.js:117
main.js:120

and then the error: at handleError (moralis.js:26416:17) line 26416 in **

handleError: function (response) {
// Transform the error into an instance of ParseError by trying to parse
// the error string as JSON
var error;

if (response && response.responseText) {
  try {
    var errorJSON = JSON.parse(response.responseText);
    **error = new _ParseError.default(errorJSON.code, errorJSON.error);**
  } catch (e) {
    // If we fail to parse the error text, that's okay.
    error = new _ParseError.default(_ParseError.default.INVALID_JSON, "Received an error with invalid JSON from Parse: ".concat(response.responseText));
  }
} else {
  var message = response.message ? response.message : response;

error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, "XMLHttpRequest
failed: ".concat((0, _stringify.default)(message)));
}

return _promise.default.reject(error);

it could be easier if you identify in network tab that request
that 400 error code looks like some parameters are invalid

You should do as @cryptokid mentioned above and also provide which token you’re swapping from and which token you’re swapping to and it’s network

thanks! also @cryptokid :slight_smile:

I found the issue. For some reason the swap uses another wallet, which is mine but I not intent to use.
There was not ETH in there so it didnt execute. I transfered some eth to test, and now the tokens are swapped in that account.

Now I need to find out why not my actual wallet triggers the swap.

It sounds like you haven’t connected your desired wallet. You can console.log Moralis.User.current().get("ethAddress") in the swap function to check.

You can clear your app’s local storage and re-authenticate.