不支持文件导入回调?

时间:2021-04-29 16:05:54

标签: solidity erc20 openzeppelin

尝试运行:

1.) Dappuniversity 项目 (dappuniversity/dbank) 2.) 宠物店教程

Truffle v5.3.3(核心:5.3.3) 节点 v14.15.5

当Truffle要求编译器/solc匹配5.3.3时,ser如何编译代码@0.8.4导入OpenZeppelin的ERC20.sol模板?

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

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

contract Token is ERC20 {

  //add minter variable

  //add minter changed event

  constructor() public payable ERC20("Name", "Symbol") {

    //asign initial minter

  }

  //Add pass minter role function

  function mint(address account, uint256 amount) public {

    //check if msg.sender have minter role

    _mint(account, amount);

  }

}

找不到源“@openzeppelin/contracts/token/ERC20/ERC20.sol”:不支持文件导入回调

2 个答案:

答案 0 :(得分:2)

错误:
Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported enter image description here

第 1 步:

安装 Solidity 扩展 enter image description here

第 2 步:

  • 右键单击错误。
  • 选择“更改默认工作区...” enter image description here

第 3 步:

选择localNodeModule
可能需要重新启动 IDE enter image description here

答案 1 :(得分:0)

ERC20 文件需要其他文件

export function getRotatedEllipseBounds(
  x: number,
  y: number,
  rx: number,
  ry: number,
  rotation: number
) {
  const c = Math.cos(rotation)
  const s = Math.sin(rotation)
  const w = Math.hypot(rx * c, ry * s)
  const h = Math.hypot(rx * s, ry * c)

  return {
    minX: x + rx - w,
    minY: y + ry - h,
    maxX: x + rx + w,
    maxY: y + ry + h,
    width: w * 2,
    height: h * 2,
  }
}

不清楚您是否正确安装了 OpenZeppelin。