Moralis Upgradeable Smart Contract Tutorial

I am having the same issue. Not sure what you are referring to when you say " delete all the ABIs in src/contracts"

Could you please elaborate? I seem to be stuck.

Which issue exactly? He means to find the .json files (ABIs) that are compiled from your contracts and delete them.

when running yarn test I also receive the error
“Error: Artifacts are from different compiler runs Run a full recompilation using truffle compile --all
https://zpl.in/upgrades/truffle-recompile-all”. Even though it compiles successfully outside of yarn test.

So I need to go through the .json files within the src/contracts folder and just make sure every reference to abi is empty? or remove the abi variable all together? and should it be deleted from every .json file in the folder or a specific one?

Sorry I understand the solidity fine. Its the web development aspect and interdependencies that are throwing me off.

So delete those artifact/JSON files that are automatically generated when you compile contracts.

You don’t need to delete any pointers to them in other files; they will be generated again after another compile. You can try that truffle compile --all command also.

Back up your project just in case.

1 Like

Ah! I see. Thank you very much. That worked perfectly. I really appreciate the quick response :handshake:

I successfully run

npm run compile

and

npm run test

However, when running

npm run migrate --network rinkeby

it always fail on error:

> Something went wrong while attempting to connect to the network at http://127.0.0.1:7545. Check your network configuration.

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 7545
    - network_id > 5777
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" or "--http" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

Truffle v5.5.11 (core: 5.5.11)
Node v16.14.2

I configured MORALIS_SPEEDY_NODES_KEY in my .env file. But for some reason it tries to connect to the localhost. Please, do you have an idea why?

How are you using your speedy node environment variable? Check your Truffle config, the rinkeby network setting is still pointing to your localhost.

Thank you, glad, for your quick response!
I’m using it the same way, how it is described in the tutorial. Relevant fragment from truffle-config.js:

module.exports = {
...
  networks: {
    develop: {
      host: "127.0.0.1",
      port: 3000,
      chainId: 1337,
      network_id: "*",
    },
...
    rinkeby: {
      provider: () =>
        new HDWalletProvider(
          mnemonic,
          `https://speedy-nodes-nyc.moralis.io/${
            process.env.MORALIS_SPEEDY_NODES_KEY
          }/eth/rinkeby${process.env.ARCHIVE === true ? "/archive" : ""}`
        ),
      network_id: 4,
      skipDryRun: true,
    },
...

What I found so far:

  • the truffle-config.js IS being used (if I delete it, I receive an error: Could not find suitable configuration file)
  • no matter what network I specify on the input, localhost is always applied. I can even use some nonsense like npm run migrate --network notConfiguredNetwork and it uses localhost anyway.

OK, I probably found the issue.
I have to run truffle develop before running truffle migrate --network rinkeby.

Is it a correct approach? I miss this step in the tutorial.

Hmm, truffle develop seems to be for using a local blockchain still. Is everything working otherwise?

Can anyone tell me why truffle compile seems to be failing. Looks like it isn’t recognizing my @openzeppelin contracts. I have tried reinstalilng the @openzeppelin/contracts a few times. I have also tried truffle compile and truffle compile --all but no luck.

Am i referencing the path wrong by doing…
import “Truffle/node_modules/@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol”;

i added the Truffle/node_modules/ to the path becasue without it wasn’t detecting and showing an error with red line under it. When i added the Truffle/node_modules/ in front the error went away but seems to be failing upon compile. Anyone have an idea what the issue may be?

Do @openzeppelin/... imports not work? What were the errors? Have you tried this?

Yes that path you’re trying isn’t working. I assume it’s trying from where that contract file is locally; not from your project root (where your public/src folders are).

yeah your path seems wrong, you can just import @openzeppelin/.. directly there since there’s node_modules under Truffle project

Thanks for the reply. As you can see when i just do @openzeppelin it says it can’t find the path, but the path is correct. Very strange. I am certain the openzeppelin contracts are installed and those are the correct paths but its not recognizing it. Worst case scenario i can try to re-download the boiler plate and start from scratch, but any idea why this might be happnening? As you can see my folder structure is the same as yours right? I also tried reinstalling with “npm install @openzeppelin/contracts” too and it still does not recognize the path. Thanks again for the help.

Okay so I finally figured out the issue. For some reason the path’s get distorted in VS Code when you have both your main project folder (Moralis-Upgradeable-Smart-Contracts) and “Truffle” open as a subfolder within the main folder. Even if you CD into Truffle and then run truffle compile it won’t recognize the @openzeppelin paths correctly. So what you have to do is close your Moralis-Upgradeable-Smart-Contract folder in VS code and just open the Truffle folder in VS Code. Once that is the only folder open there is no problem.

Tbh this is first time i have ever had the files structured this way with 2 different node-module folders and 2 different .env folders. I think perhaps this isn’t the best way to design the project. I realize one is for the front end and one is for the back-end so logically it makes sense but i think paths are getting distorted, meaning you can’t have both front-end and back-end projects open within VS code at the same time. At least in my experience this caused some problems and tbh i saw it coming from the get-go when i saw the folder structure. At the same time I am not a veteran coder so maybe this file structure is more common than i think, but nonetheless it caused some issues for me.

Anyway for anyone reading this was the solution in case you run into the same issue. Rest of the tutorial is great so kudos to Yoseph for putting it together.

1 Like