0

I am trying to deploy my first smart contract on ganache blockchain. The compilation of my NFT goes well but when I try the "truffle migrate" command it gives me the error in the pic. The code of my contract is really simple, I paste it here:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "hardhat/console.sol";

contract MyToken is ERC721 {

    constructor() ERC721("MyToken", "MTK") {}

}

enter image description here

I tried the way described in this issue: "Migrations" hit an invalid opcode while deploying on deploy Migrations.sol with Truffle but didn't solve my problem.

2
  • Which network are you using? Is it a private network? If that is the case it could be that the genesis didn't enable all the opcodes.
    – Ismael
    Commented May 17, 2023 at 1:57
  • 1
    Thanks for your answer, I decide to create a new project and It worked without any problem Commented May 18, 2023 at 7:05

2 Answers 2

1

Downgrading solc from 0.8.20 to 0.8.13 resolved the problem for me.

I got to that version by downloading the metacoin truffle box, verifying that migration works and then getting the version of solc from the truffle-config.js of the project.

It is worth doing the same, rather than using the specific solc version that resolved this for me at this point in time, as Truffle will probably update the metacoin box eventually to keep up with the rest of their tools and this number will get out of date.

Downloading the metacoin truffle box is as easy as this:

truffle unbox metacoin [PATH/TO/DIRECTORY]

2
  • Hi MichelinMan! Do not copy & paste the same answer multiple times. If you think the questions are the same you can flag them as duplicates.
    – Ismael
    Commented Jul 19, 2023 at 19:58
  • Thank you, noted, I will do so going forward. Commented Jul 20, 2023 at 8:46
1

in your truffle-config.js downgrade to :

compilers: { solc: { version: "0.8.17", }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.