Equivalent syntax for Cloud function web3ByChain("0x4")

Hi, can anyone tell me the equivalent syntax to convert Moralis.web3ByChain(“0x13881”) from Cloud function to a frontend client JS code?

And do I need to enableWeb3() first before getting the web3 instance on Mumbai ?

Thanks in advance!

you can do that in front end only by using ethers or web3 and using the RPC node url, something similar to how you would do it in cloud code with a custom RPC url:
https://docs.moralis.io/moralis-dapp/cloud-code/cloud-functions#example-of-how-to-use-a-custom-rpc-url

Thank you! Let me give it a try!

import { ethers } from "ethers";
  const web3Provider = new ethers.providers.JsonRpcProvider(NETWORK_CHAIN);
  const marketplaceAbi ='[... ]';
  const gateway = new ethers.Wallet(GATEWAY_PRIVATE_KEY, web3Provider);
  const marketplace = new ethers.Contract(
    MARKETPLACE_ADDRESS,
    JSON.parse(marketplaceAbi),
    gateway,
  );

For anyone who needs help with!

2 Likes