[SOLVED] Self-hosting Parse Server unknown parameter: address issue

Hi,
I’ve successfully setup a self-hosting parse server.
But, I’m getting unknown parameter: address error while using some APIs from moralis-v1.

For example, I call this function:
Moralis.Web3API.token.getTokenMetadata({ chain: chainId, addresses: [address], })
Apparently, the library adds the address parameter (address of the connected wallet), and parse server returns the error.

I’m using moralis-v1: 1.12.0.

And, the same problem occured with Moralis.Web3API.storage.uploadFolder as well.

What is the solution for this?

Thanks in advance.

Hey @PWDev

Not sure about the uploadFolder error since there are no address parameter

However, would like to know base on the error message there whether address is defined?

hey @YosephKS,

I’ve tried to debug again and what I’ve found out is:

address parameter is added to the params object at https://github.com/MoralisWeb3/Moralis-JS-SDK-v1/blob/327752d15aa7ff6519d01e7865887cc8795dbcc1/src/MoralisWeb3Api.js#L102

and the request cannot pass the validation on parser server at https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/11b751d983adea43b3d9ce2513b3148aca4afa32/packages/common/core/src/operations/OperationRequestValidator.ts#L15

because address parameter doesn’t exist in any of parameter arrays at https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/main/packages/common/evmUtils/src/operations/token/getTokenMetadataOperation.ts since getTokenMetadataOperation is described as below:

export const getTokenMetadataOperation: Operation<
  GetTokenMetadataRequest,
  GetTokenMetadataJSONRequest,
  GetTokenMetadataResponse,
  GetTokenMetadataJSONResponse
> = {
  method: 'GET',
  name: 'getTokenMetadata',
  id: 'getTokenMetadata',
  groupName: 'token',
  urlPathPattern: '/erc20/metadata',
  urlSearchParamNames: ['chain', 'addresses'],

  getRequestUrlParams,
  serializeRequest,
  deserializeRequest,
  deserializeResponse,
};

Can you look in network tab to see what is sent for that request?

hi @cryptokid,
Request is sent to http://localhost:1337/server/functions/getTokenMetadata

And below is the payload:

{
    "chain": "0xa869",
    "addresses": [
        "0xa4116d0376C82826f651d970dD612D8f0a1f9982"
    ],
    "address": "0xb7d4fe4d869245f17483d03a46cbd15a9ebc017d",
    "_SessionToken": "r:7929af406f4c4d36a71e86ec0cbe855c",
    "_ApplicationId": "hbGuJXKBkx01Nw4FqVhcHXpSVGeLX5PZJIBRYAlV"
}

And here is how it fails:

Where from did you get that address parameter? I mean the name of the parameter.

Also, what version of the sdk you are using?

I guess, you are asking the name in error message, right?

It is resolved at https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/11b751d983adea43b3d9ce2513b3148aca4afa32/packages/common/core/src/operations/OperationRequestValidator.ts#L15 on parse-server.

public validate(request: Request) {
    const requestParamNames = Object.keys(request as Record<string, unknown>);

    for (const paramName of requestParamNames) {
      if (!this.allParamNames.includes(paramName as keyof Request)) {
        const allParamsNames = this.allParamNames.join(', ');
        throw new MoralisError({
          code: CoreErrorCode.INVALID_ARGUMENT,
          message: `Request contains unknown parameter: ${paramName}. This operation supports the following parameters: ${allParamsNames}`,
        });
      }
    }
  }

I’m using moralis-v1: 1.12.0 on client app.

In backend I guess that is the error. And I guess that you don’t use Moralis v1 in backend

if this is the endpoint you want to use, it has only addresses parameter:

actually, there is no backend in this scenario.
moralis-v1 library adds address parameter and calls my self-hosted parse server directly from the frontend.
The validation on parse server fails and returns the error.

Is this an incorrect way of using moralis-v1 library?

that is the backend, the self hosted parse server

how are you calling that function in front end? with what parameters?

you say that you don’t add address parameter but somehow it is added automatically?

maybe it is an issue with moralis v1 sdk if it adds that address automatically, you can call directly the cloud function for getTokenMetadata with the expected parameters

Yeah, I think there are some incompatibilities between moralis-v1 sdk and parse server validations.

The same problem happens with Moralis.Web3API.storage.uploadFolder function as well. moralis-v1 sdk adds address parameter to the request and parse server validation returns unknown parameter error.

Moralis.Web3API.native.runContractFunction fails with function_name parameter although it was working fine earlier with Moralis cloud servers.

I have only experienced these so far, the same issue may apply for more APIs.

So, would Moralis consider fixing these issues within the libraries used by parse server or with another moralis-v1 SDK version? Or, shall I figure out my own workarounds?

Thanks,

it should be fixed now, you have to update parse-server-migration to latest version

seems like it is not working :frowning:

params parameter in all the cloud function definitions is changed to request in https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/main/demos/parse-server-migration/src/cloud/generated/evmApi.ts , and apparently that’s why this error occurs.

For example for getTokenMetadata, the cloud function definition was Parse.Cloud.define("getTokenMetadata", async ({params, user, ip}: any) => { and changed as below:

const getTokenMetadataOperation = getOperation('getTokenMetadata');
Parse.Cloud.define("getTokenMetadata", async ({request, user, ip}: any) => {
  try {
    await beforeApiRequest(user, ip, 'getTokenMetadata');
    upgradeRequest(request, getTokenMetadataOperation);
    const result = await Moralis.EvmApi.token.getTokenMetadata(request);
    return result?.raw;
  } catch (error) {
    throw new Error(getErrorMessage(error, 'getTokenMetadata'));
  }
})

I tried changing request to params for test purpose and it worked fine.

you have a working version now?

I only tried for getTokenMetadata.

I changed the parse-server code at https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/main/demos/parse-server-migration/src/cloud/generated/evmApi.ts as

const getTokenMetadataOperation = getOperation('getTokenMetadata');
Parse.Cloud.define("getTokenMetadata", async ({params, user, ip}: any) => {
  try {
    await beforeApiRequest(user, ip, 'getTokenMetadata');
    upgradeRequest(params, getTokenMetadataOperation);
    const result = await Moralis.EvmApi.token.getTokenMetadata(params);
    return result?.raw;
  } catch (error) {
    throw new Error(getErrorMessage(error, 'getTokenMetadata'));
  }
})

and it worked fine.

I think, this needs to be changed for all cloud function definitions in the same file.

Try again with the latest version. We didn’t another fix.

hey @cryptokid,
The new version works fine with getTokenMetadata, but it still has a problem with uploadFolder.

chain parameter is added automatically by moralis-v1 sdk, and parse-server validation fails with unknown parameter.

Also, parse-server validation still fails with unknown parameter error for Moralis.Web3API.native.runContractFunction when function_name parameter is used, although it was working fine earlier with Moralis cloud servers.

I’ll send the feedback to the team