Venture-Miner / Linea-Dev-Cook-Off-Mini-Bootcamp

Material for the Linea Dev Cook-Off Mini-Bootcamp
GNU General Public License v3.0
9 stars 2 forks source link

Error during ERC20 'FrogToken' deployment via Remix ( VM London and Linea Sepolia) #3

Closed scripnichenko closed 5 months ago

scripnichenko commented 5 months ago

Problem

Given a code snippet from Part1 Tutorial

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract FrogToken is ERC20, ERC20Permit {
    constructor() ERC20("FrogToken", "FROG") ERC20Permit("FrogToken") {
        _mint(msg.sender, 1000 * 10 ** decimals());
    }
}

1. Attempt to deploy to Local (Remix VM London)

Error:

[vm]from: 0x5B3...eddC4to: FrogToken.(constructor)value: 0 weidata: 0x610...40033logs: 0hash: 0x318...a3cf2
creation of FrogToken errored: Error occurred: invalid opcode.

invalid opcode

    The execution might have thrown OR the EVM version used by the selected environment is not compatible with the compiler EVM version.

Debug the transaction to get more information.

2. Attempt to deploy to Injected Provider - Metamask

Error:

image

After accepting next error appears:

image
MatheusDaros commented 5 months ago

Hello @scripnichenko

Thanks for opening this issue. We had this problem in our lesson as well, and we did not have enought time to fix it live. For using solidity version 0.8.19 we can't use the recent versions of OpenZeppelin Contracts, that require solidity 0.8.20 or above. So in our case we would need to use older versions of OpenZeppelin Contracts to import the token contracts to use in our token.

The fixed code would look like this:

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

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.9/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.9/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract FrogToken is ERC20, ERC20Permit {
    constructor() ERC20("FrogToken", "FROG") ERC20Permit("FrogToken") {
        _mint(msg.sender, 1000 * 10 ** decimals());
    }
}

Notice how we're specifying the branch release-v4.9 when importing, instead of picking the default that would be the latest release.

scripnichenko commented 5 months ago

Works now! Thanks, @MatheusDaros for info.

image
mpereyras commented 4 months ago

image I get a gas error, so I put the version directly: pragma solidity 0.8.19;