【问题标题】:hardhat 'pragma solidity' marked as unexpected identifierhardhat \'pragma solidity\' marked as unexpected identifier
【发布时间】:2022-12-02 00:10:10
【问题描述】:

I have been working on my ethereum project when face with issue new contracts stops compiling with error message:

blockchain/contracts/Utils.sol:2
pragma solidity ^0.8.9;
       ^^^^^^^^

SyntaxError: Unexpected identifier 

I simply can not create a new contract anymore. It looks like there is some break in the environment.

Have you ever face with this issue? Do you have any thoughts what is wrong here?

Hardhat config is:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  solidity: "0.8.9",
};

export default config;

【问题讨论】:

  • it's possible it's missing a ; in the line above (?)
  • Thank you, I have found the issue in import the contract into the test .ts file. See my answer below.

标签: ethereum solidity


【解决方案1】:

The issue was in import in .ts file.

My current import for test is shown below:

import { expect } from "chai";
import { ethers } from "hardhat";
import { utils, BigNumber } from "ethers";
import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import "../contracts/Utils.sol";

Remove import "../contracts/Utils.sol"; from import solves the issue.

It is redundant import, hardhat is able to evaluate type of the contract just by its name in the factory. The root cause though is unclear.

【讨论】:

    【解决方案2】:

    In Hardhat, this error occurs while running .sol Hardhat this error occurs while running .sol contract instead of .js deployment script

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 2021-06-09
      • 2019-09-16
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多