0

I'm trying to deploy an ERC20 contract, but I keep getting an invalid opcode error. Below is my contract and a screenshot from REMIX:

pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor(
        string memory name,
        string memory symbol,
        uint256 initialSupply,
        address initialOwner
    ) ERC20(name, symbol) Ownable(initialOwner) {
        _mint(msg.sender, initialSupply);
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }

    function burn(address from, uint256 amount) public onlyOwner {
        _burn(from, amount);
    }
}

enter image description here

2
  • can you confirm what solidity version you used to compile this with?
    – Zaryab
    Commented Jul 27 at 21:28
  • 0.8.20+commit.a1b79de6 @Zaryab Commented Jul 27 at 21:52

1 Answer 1

0

Try to use a more recent VM, I suggest Shanghai or Cancun, both should work:

enter image description here

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.