Local Moralis Setup with Hardhat

Hello,

Iā€™m trying to figure out how to use Moralis in a development environment, connecting to a local hardhat node. Is there documentation on running Moralis locally, Iā€™ve seen a migration server (https://moralisweb3.github.io/Moralis-JS-SDK/demos/parse-server-migration/) but struggling to find documentation on running the self hosted server and using that with a local node.

It seems like I need to set up a self-hosted server (https://moralis.io/how-to-set-up-a-self-hosted-web3-server/) but after that I havenā€™t been able to find documentation on using that locally for development with hardhat.

Hello, after you manage to run your self hosted server, you can try to use the code posted in this forum post:

Hey @cryptokid thanks for the reply! Checking out the code linked, it looks like I have to manually add each event from local contracts to get them to save to the database?

I think that you can use that watchContractEvent cloud function to add them

Ok gotcha thank you! Once Iā€™ve got my self hosted server running and the watchContractEvent function set up, how do I configure my API server to hit the self hosted Moralis server? It looks like the config option only take an api key from what I can tell.

Moralis.default.start({
  apiKey: process.env.MORALIS_API_KEY
});

What do you mean with this? What api?

I have an expressjs api that uses Moralis, I want to call my self-hosted server from this api for local development.
For example, this call

await Moralis.EvmApi.nft.getWalletNFTs({
    disableTotal: true,
    address: 'an address',
     chain
  });

web3api will not work with hardhat, only with a chain that we support in web3api

Thatā€™s kind of surprising, a developer focused platform doesnā€™t support a standard development workflow using hardhat local node. Does everyone just use testnets when working with Moralis in development? Seems odd to me, feel like Iā€™m missing something. I always run everything locally in development.

using web3api is more complex than using a RPC node url, for example to get all the nfts for a contract or of the list of nfts for a wallet address.

it will work with a testnet network, you can still test limited functionality with your local development environment like event syncs