Moralis self hosted server with vanilla js

@johnversus here if u can see in console.log(error) in catch

await checkTokenAddress(token_address)
        .then(async (exists) => {
          if (exists) {
            token_loading = false;
            token_already_used = true;
            setTimeout(() => {
              token_already_used = false;
            }, 3000);
          } else {
            try {
              token_already_used = false;
              const metadata = await getTokenMetadata(token_address, chainId);
              token_metadata = metadata[0];

              token_loading = false;
            } catch (error) {
              console.log(error)
              token_loading = false;
              token_error = true;


@johnversus is it possible that it may the issue of moralis version because as of now i am using version 2

You definition of getTokenMetadata looks ok to me. However the value addresses accepts an array of addresses as value. Can you verify if you are passing an array of contract addresses as a param value?

@johnversus i have given in array address

  if (chainId == "0x61") {
    //Get metadata for one token. Ex: USDT token on ETH
    options = {
      chain: "bsc testnet",
      addresses: [token_address],
    };

but still same errro

Ok…Let me test it on my end and will let you know.

ok sure @johnversus
thanks
meanwhile i am also looking into it

When I try calling it like this I can see it working without any error.

    const data = await Moralis.Web3API.token.getTokenMetadata({
      addresses: ["0xdac17f958d2ee523a2206206994597c13d831ec7"],
      chain: "0x1",
    });

Could it be possible that the value of your final options is an empty object {}? So there are no valid param values passed to getTokenMetadata function?

It could happen if the chainId is not equal to "0x38" or β€œ0x61”.

@johnversus
i also given in this way but it’s not working for
is there any moralis version issue?
which version u are using

export async function getTokenMetadata(token_address, chainId) {
  let options = {};

  if (chainId == "0x61") {
    //Get metadata for one token. Ex: USDT token on ETH
    options = {
      chain: "bsc testnet",
      addresses: [token_address],
    };
  } else if (chainId == "0x38") {
    //Get metadata for one token. Ex: USDT token on ETH
    options = {
      chain: "bsc",
      addresses: token_address,
    };
  }

  const tokenMetadata = await Moralis.Web3API.token.getTokenMetadata({
    addresses: ['0xE4879C93aE512E12DA25308D89eca6383c08432B'],
    chain: "0x61",

  });

  // const isLP = new ethers.Contract('0xB7926C0430Afb07AA7DEfDE6DA862aE0Bde767bc', Factory)
  // const abc = await isLP.getPair('0x69859eB3160ad104E268725f4d310B8cD2f56E8F', '0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd' )
  // // console.log(abc)
  
  const getLp= await getIsLPTOken(chainId, token_address)
  let isLP= false
  if(getLp != ethers.constants.AddressZero){
       isLP=true
  }
  // console.log(isLP)
  

  const totalSupply = await getTotalSupply(token_address);

  const formattedSupply = ethers.utils.formatUnits(
    totalSupply.toString(),
    tokenMetadata[0].decimals
  );

  const walletBalance = await getBalanceOf(
    token_address,
    Moralis.User.current().get("ethAddress")
  );

  const formattedBalance = ethers.utils.formatUnits(
    walletBalance.toString(),
    tokenMetadata[0].decimals
  );
  

  tokenMetadata[0].balance = formattedBalance;
  tokenMetadata[0].totalSupply = formattedSupply;
 tokenMetadata[0].isLP=isLP;
  return tokenMetadata;
}

I tried with the latest code form this repo

Maybe try adding any console.log to find out correct expected param values are being passed to the function.

could u pls confirm which moralis version u are using and also if possible could u pls provide the exact file name in which we can go and check the code from the above git repo u provided

This is the part of code which is related to getTokenMetadata functions. It is present in src/cloud/generated/evmApi.ts file path.

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

I have "moralis": "^2.22.0" in backend and "moralis-v1": "^1.12.0", on frontend

@johnversus we are also using the same version but still it’s not working

for me i am able to authenticate self hosted with moralis version 2 as well

I dont see anything missing in your code.

Can you once try restarting the backend and fronted localhost? And also add some console.logs to know if you are passing the correct data to the getTokenMetadata contract

@johnversus i have restarted server as well but not working
is there any dependency that i am missing?

I dont think there is any dependancy missing. can you debug further using console.logs?

@johnversus i did the console log but it 's showing error
unknown parameter: address. This operation supports the following parameters: chain, addresses

The error feels strange because you did not use address anywhere in getTokenMetadata function.

Do you think we are looking at the wrong part of the code for the error? :sweat_smile:

@johnversus is it possible for u to connect in meet :sweat_smile:
it would be really helpful for me

Might not be possible now :sweat_smile:. Is it possible for me to have a closer look on the code? If possible you can share the github repo