[SOLVED] Calling Moralis JS SDK V2 directly from javascript

Hi there!
I have been successfully using the previous Moralis V1 SDK by simply including both the unpkg Moralis V1 script and the npm web3 inside a PHP page of a large project for authenticating users and displaying their NFTs.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/moralis.js"></script>

<script>
      // connect to Moralis server
	
      const serverUrl = "https://fsuzdyamcfga.usemoralis.com:2053/server";
      const appId = "4sdrxxxxxxxxxcbQ";
	  const masterKey = "LVxxxxxxxxxetd";
	  const moralisSecret = "HtTxxxxxxxxUf";
      Moralis.start({ serverUrl, appId, masterKey });
</script>

Since there is no for V2, how can I continue using these Moralis features in my PHP site? Do I need to self-host the new Moralis SDK and call it somehow? I am sure many others where using the script with simple javascript to access such features and can’t find any workaround. Thanks in advance!

You can always make direct HTTP requests to the Moralis API. Otherwise the easiest way for you could be to self-host your server so you can keep using moralis-v1 and the same type of code.

That sounds great… For displaying NFTs from an address I could manage it with a simple GET request I suppose. But regarding Metamask and Phantom authentication, what would be the best approach? I do not need to save any data. Just to grab the information and display it, I then use PHP to save it in my database.

What sort of info do you want to display? If it’s only the address/chain then you could just connect the wallet normally e.g. with MetaMask. Otherwise you can look into self-hosting.

Great! that works, have any git for solana > phantom wallet connection? Many thanks

You can check out this page for Phantom.

Many thanks! Regarding the GET NFTs by Wallet for solana API I am getting a 400 Bad Request from the API reference page: https://docs.moralis.io/reference/getsolnfts

EVM works fine.

That is a known issue - it will work if you select devnet then mainnet again.

Thank you Alex, everything has been working perfect for a while. But suddenly today I realized I can not display any NFTs and get the console message: API KEY is currently blocked

How can I get this fixed? Many thanks

Hey @ricardopico,

Looks like if it’s an API key issue, then it is different issue and I will suggest that you contact us through [email protected].

Quick note as well that the issue for calling Solana API through the documentation is no longer a problem and have been fixed.