1INCH Plugin Error - from address mismatch

When I try to use hasAllowance function, I get an error. And I do not know what to do.

the code I start on load:

const serverUrl = 'my server url' ;
const appId = 'my app id';
await Moralis.start({ serverUrl, appId });
await Moralis.initPlugins();
await Moralis.enableWeb3();

my code (userAddress and fromToken.address works okay):

async function hasAllowance() {
    const allowance = await Moralis.Plugins.oneInch.hasAllowance({
        chain: 'bsc',
        fromTokenAddress: fromToken.address,
        fromAddress: userAddress,
        amount: '1000000',
    });
    console.log(`The user has enough allowance: ${allowance}`);
}

My payload:

1. amount: "1000000"
2. chain: "bsc"
3. fromAddress: "0x249c0b91b8825ac08f811a7cb5c6b2d490a194c1"
4. fromTokenAddress: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
5. _ApplicationId: "37q2D...(I deleted it)"
6. _ClientVersion: "js1.6.0"
7. _InstallationId: "6b6d901b-f03e-48c5-8923-cae0e8e9dfc6"
8. _SessionToken: "r:d8b28a68e60903752e21ca8c132eb3ff"

The response:
{"code":141,"error":{"status":502,"headers":{"x-powered-by":"Express","access-control-allow-origin":"*","content-type":"application/json; charset=utf-8","content-length":"24","etag":"W/\"18-py7kky+nYw+KpM//zLTacYk1OLw\"","x-response-time":"52.047ms","date":"Thu, 05 May 2022 22:20:26 GMT","connection":"close"},"buffer":{"type":"Buffer","data":[123,34,101,114,114,111,114,34,58,116,114,117,101,44,34,100,97,116,97,34,58,123,125,125]},"text":"{\"error\":true,\"data\":{}}","data":{"error":true,"data":{}}}}

Thanks!

Hi I tried running your hasAllowance example, it doesn’t work with that fromTokenAddress (400 Bad Request) because it’s not valid. It needs to be the token address for the token you want to swap.

Can you make sure your Moralis server is running with the 1inch plugin installed. Otherwise you may need to try using the latest Moralis SDK version as I see you’re using Moralis.initPlugins() which isn’t documented anymore.

1 Like

Hey, thanks for the help.
After changing the token I still get the error.
Payload:

amount: "1000000"
chain: "bsc"
fromAddress: "0x249c0b91b8825ac08f811a7cb5c6b2d490a194c1"
fromTokenAddress: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82"
_ApplicationId: "I deleted"
_ClientVersion: "js1.6.0"
_InstallationId: "6b6d901b-f03e-48c5-8923-cae0e8e9dfc6"
_SessionToken: "r:d8b28a68e60903752e21ca8c132eb3ff"

Response:

{"code":141,"error":{"status":502,"headers":{"x-powered-by":"Express","access-control-allow-origin":"*","content-type":"application/json; charset=utf-8","content-length":"24","etag":"W/\"18-py7kky+nYw+KpM//zLTacYk1OLw\"","x-response-time":"31.238ms","date":"Thu, 05 May 2022 23:37:29 GMT","connection":"close"},"buffer":{"type":"Buffer","data":[123,34,101,114,114,111,114,34,58,116,114,117,101,44,34,100,97,116,97,34,58,123,125,125]},"text":"{\"error\":true,\"data\":{}}","data":{"error":true,"data":{}}}}

When I try using Swagger API without moralis it is successfull. (https://api.1inch.io/v4.0/56/approve/allowance?tokenAddress=0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82&walletAddress=0x249c0b91b8825ac08f811a7cb5c6b2d490a194c1). I might use this without moralis but I also want to know why it doesn’t work.

And about the plugin, it is installed and updated to latest version.

Your example now is working for me.

async function hasAllowance() {
  const allowance = await Moralis.Plugins.oneInch.hasAllowance({
    chain: 'bsc',
    fromTokenAddress: '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82',
    fromAddress: '0x249c0b91b8825ac08f811a7cb5c6b2d490a194c1',
    amount: '1000000',
  });
  console.log(`The user has enough allowance: ${allowance}`);
}

which returns The user has enough allowance: false.

Can you try using another server with 1inch plugin?

hey, thanks for all the help!
after getting a brand new server it works perfect!

2 Likes