文件導入回調不支持 import ‘./IERC20.sol’;
當我嘗試編譯我的契約時,我看到這樣的錯誤:
DemirelToken.sol
https://eksiup.com/p/4z49413damc3
這是程式碼:
pragma solidity ^0.5.0; import "node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; contract DemirelToken is ERC20, ERC20Detailed { constructor(uint256 initialSupply) ERC20Detailed("Gold", "GLD", 18) public { _mint(msg.sender, initialSupply); } }
我收到這樣的錯誤:
node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol:3:1: ParserError: Source “node_modules/openzeppelin-solidity/contracts/token/ERC20/IERC20.sol” not found: File import callback not supported import " ./IERC20.sol"; ^——————–^ ,node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol:4:1: ParserError: Source “node_modules/openzeppelin -solidity/contracts/math/SafeMath.sol”未找到:文件導入回調不支持導入“../../math/SafeMath.sol”;^——————-^ ,node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol: 3:1: ParserError: Source “node_modules/openzeppelin-solidity/contracts/token/ERC20/IERC20.sol” not found: File import callback not supported import “./IERC20.sol”;
您需要修復導入中的路徑:
pragma solidity ^0.5.0; import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; contract DemirelToken is ERC20, ERC20Detailed { constructor(uint256 initialSupply) ERC20Detailed("Gold", "GLD", 18) public { _mint(msg.sender, initialSupply); } }
確保您在項目中安裝了 openzeppelin-solidity
npm install openzeppelin-solidity
您的導入如下:
pragma solidity ^0.5.0; import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; contract DemirelToken is ERC20, ERC20Detailed { constructor(uint256 initialSupply) ERC20Detailed("Gold", "GLD", 18) public { _mint(msg.sender, initialSupply); } }