Build Medium Clone! - Moralis Project going live on the 18th of June

In this thread please ask any questions about Moralis Project ‘Build Medium Clone!’ that will be going
live on the 18th of June. We will help right away!

Project video:
https://www.youtube.com/watch?v=8S8unFCq0fM

3 Likes

[email protected]: The engine "node" is incompatible with this module. Expected version "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0". Got "16.5.0"

[email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
error [email protected]: The engine "node" is incompatible with this module. Expected version "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0". Got "16.5.0"
error Found incompatible module.

You can try switch your node to version 16.10.0

1 Like

v16.5.0

this version i have install

You can still downgrade it or install both and switch between versions using nvm

1 Like

yes … thanks I am search how update node thanks…

yeeeesss thanks only update node and ready thanks

1 Like

Hi! I am trying to do the Medium project, however, I do not understand why when I am tryna connect my MM wallet, I am somehow stuck in the process. I sign the request from my MM, but i cannot enter the app. It is stuck on the second picture :confused: IDK why!
It is related to the App.js file I suppose

Cannot read property 'slice' of undefined

You can check if you got some errors in your console

You’re trying to call slice method on a property that’s not defined as mentioned. You can make a little fix by adding a question mark before the slice like ?.slice, this will call slice if the variable exist or you can find a way to make sure the variable is defined

address(this) is the contract address where this transfer function is being run on. So that will transfer the contract’s balance to the msg.sender (the address calling the contract) - the purpose is to “return oversupplied fees”. The tutorial should cover what each part of the contract does.

Got it thanks. Watched the video.

Quick question:

How would I add multiple chains that Moralis doesn’t support yet?

Mainly I would like add: HarmonyONE Testnet.

Would I just use the HarmonyONE Testnet RPC? and put it into the code?

I tried looking here but Moralis doesn’t support Harmony yet: https://docs.moralis.io/moralis-dapp/web3-api/supported-chains

Is there a way to manually add chains with the chain ID and RPC and block explorer info?

Also, in the video Jay only chose the polygon mumbai chain but I want to use multiple testnets.

Also, if you want me to learn and want to not give the exact answer then can you tell which docs to look at any tutorials I should look up?

Would I change the code like this here:

For the HomeAuth.js

 const options = {
      chain: "mumbai",
      address: "xxxx",    
    };
 const options = {
      chain: "avalanche testnet",
      address: "xxxx",
   };
 const options = {
      chain: "bsc testnet",
      address: "xxxx",
 };
 const options = {
      chain: "goerli",
      address: "xxxx",  
   };```

And For MyBlogs.js:

const options = {
      chain: "mumbai",
      address: account,
      token_address: "xxx",
    };
 const options = {
      chain: "avalanche testnet",
      address: account,
      token_address: "xxxx",
    };
 const options = {
      chain: "bsc testnet",
      address: account,
      token_address: "xxxx",
    };
 const options = {
      chain: "goerli",
      address: account,
      token_address: "xxxx",
    };

And For NewStory.js:

How would I make it so that:

If wallet is connect to BSC testnet then use this contract address and same for rest of the chains.

Or can I just add the other contract addresses below it like this:

let options ={
      contractAddress: "xxxx",
      contractAddress: "xxxx",
      contractAddress: "xxxx",
      contractAddress: "xxxx",
      functionName: "safeMint",
      abi: [
        {
          inputs: [
            {
              internalType: "address",
              name: "to",
              type: "address",
            },
            {
              internalType: "string",
              name: "uri",
              type: "string",
            },
          ],
          name: "safeMint",
          outputs: [],
          stateMutability: "payable",
          type: "function",
        },
      ],
      params: {
        to: account,
        uri: uri,
      },
      msgValue: Moralis.Units.ETH(1),
    }

I’m guessing I would need to specify which contracts are for which chain and I’m guessing it wouldn’t automatically just work on every chain because, there is no specifications yet for what the contract address is for that chain?

Or am I totally wrong and moralis can just handle all of that and all I need to is something really simple like putting all of the contract addresses in one place?

How would I add multiple chains that Moralis doesn’t support yet?

Yes as Harmony isn’t supported by Moralis then use of the Moralis API or syncing data to server for that chain won’t work.

Also, in the video Jay only chose the polygon mumbai chain but I want to use multiple testnets.

If you want to change the chain used, you will need to deploy the Medium smart contract on that chain and then change those options objects.

If wallet is connect to BSC testnet then use this contract address and same for rest of the chains.

You can do a check for the user’s current chain (you can use chainId from the useMoralis hook) and then change the chain used in any options.

let options ={
contractAddress: “xxxx”,
contractAddress: “xxxx”,
contractAddress: “xxxx”,
contractAddress: “xxxx”,

You won’t be able to do this, you can use only one contractAddress. Same as above, based on the current chainId, you could select the right contract address from an object of addresses (maybe in a separate .js file that you import).

1 Like

This makes sense thank you.

Question: How would I make it so that I put in details for multiple contracts and multiple chains?

Let’s say you deploy the Medium Final Contract on BSC Testnet, Avax Testnet & ETH Goerli Testnet

Then how would you specify the custom contract addresses for each of those chains? and allow the dapp to automatically switch either of those chains when a user is on one of those chains?

You can have all the contracts in an object and then you could use chainId from useMoralis to get the current chain and select the right address.

function Component() {
  const { chainId } = useMoralis();

  async function run() {
    const contracts = {
      '0x13881': 'mumbaiaddress', // Mumbai
      '0x61': 'bsctestnetaddress', // BSC testnet
    };

    let options = {
      contractAddress: contracts[chainId],
      // rest of code
    };

    // rest of code
  }
}
1 Like

This was really helpful thank you very much!