简体   繁体   English

在默认本地 ganache 上部署时,Brownie ParserError openzeppelin/contracts/token/ERC20/ERC20.sol

[英]Brownie ParserError openzeppelin/contracts/token/ERC20/ERC20.sol when deploying on default local ganache

ParserError: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File not found.

While I'm deploying with brownie on default local ganache-cli.当我在默认的本地 ganache-cli 上使用 brownie 进行部署时。

Command:命令:

$ brownie compile

gets:得到:

Brownie v1.17.2 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.8.11
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
CompilerError: solc returned the following errors:

ParserError: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File not found.

Token file head:令牌文件头:

pragma solidity ^0.8.0;

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

contract InvestToken is ERC20 {

brownie-config.yaml file:布朗尼-config.yaml 文件:

dependencies:
  # - <organization/repo>@<version>
  - OpenZeppelin/openzeppelin-contracts@4.4.2
compiler:
  solc:
    remappings:
      - '@openzeppelin = OpenZeppelin/openzeppelin-contracts@4.4.2'

command:命令:

$brownie pm install OpenZeppelin/openzeppelin-contracts@4.4.2

gets:得到:

FileExistsError("Package is aleady installed")

I made a mistake in the brownie-config.yaml file:我在 brownie-config.yaml 文件中犯了一个错误:

I wrote:我写:

remappings:
      - '@openzeppelin = OpenZeppelin/openzeppelin-contracts@4.4.2'

and it is它是

remappings:
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.4.2'

sorry about that对于那个很抱歉

Base on your error I think is relate with brownie-config.yaml when new line don't use tab, use space根据您的错误,我认为与 brownie-config.yaml 相关,当新行不使用制表符时,请使用空格

my issue with brownie-config.yaml我对 brownie-config.yaml 的问题

dependencies: 
  - OpenZeppelin/openzeppelin-contracts@4.2.0
compiler: 
  solc: 
    ramappings: 
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.2.0'
dotenv: .env
wallets: 
  from_key: ${PRIVATE_KEY}

when I fixed form tab to space当我将表单选项卡固定到空格时

dependencies:
 - OpenZeppelin/openzeppelin-contracts@4.2.0
compiler:
 solc:
  remappings:
    - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.2.0'
dotenv: .env
wallets:
  from_key: ${PRIVATE_KEY}

also u can check ref from Patrick:你也可以查看帕特里克的参考

Skip to content跳到内容

OpenZeppelin/openzeppelin-contractsPublic OpenZeppelin/openzeppelin-contractsPublic

CodeIssues116Pull requests30ActionsSecurity11Insights CodeIssues116Pull requests30ActionsSecurity11Insights

master掌握

openzeppelin-contracts/contracts/token/ERC20/ERC20.sol openzeppelin-contracts/contracts/token/ERC20/ERC20.sol

tonynoce " class="Link--secondary" href="https://github.com/OpenZeppelin/openzeppelin-contracts/commit/5e7e9acfa4630c1f933f7e8435ccc4490cacb274" style="box-sizing: border-box; tonynoce " class="Link--secondary" href="https://github.com/OpenZeppelin/openzeppelin-contracts/commit/5e7e9acfa4630c1f933f7e8435ccc4490cacb274" style="box-sizing:border-box; background-color: transparent;背景颜色:透明; color: var(--color-fg-muted);important: text-decoration;颜色:var(--color-fg-muted);重要:文本装饰; none:">Fix broken forum URL (#3537" class="Link--secondary" href="https.//github:com/OpenZeppelin/openzeppelin-contracts/commit/5e7e9acfa4630c1f933f7e8435ccc4490cacb274" style="box-sizing; border-box: background-color; transparent: color; var(--color-fg-muted):important; text-decoration: none;">) none:">修复损坏的论坛 URL (#3537" class="Link--secondary" href="https.//github:com/OpenZeppelin/openzeppelin-contracts/commit/5e7e9acfa4630c1f933f7e8435ccc4490cacb274" style="box-sizing;框:背景颜色;透明:颜色;var(--color-fg-muted):重要;文本装饰:无;">)

42 contributors+26 42 位贡献者+26

389 lines (351 sloc) 12.7 KB 389 行 (351 sloc) 12.7 KB

// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; // SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol";import "./extensions/IERC20Metadata.sol";import "../../utils/Context.sol";导入“./IERC20.sol”;导入“./extensions/IERC20Metadata.sol”;导入“../../utils/Context.sol”; /** * @dev Implementation of the {IERC20} interface. /** * @dev 实现 {IERC20} 接口。 * * This implementation is agnostic to the way tokens are created. * * 此实现与创建令牌的方式无关。 This means * that a supply mechanism has to be added in a derived contract using { mint}.这意味着 * 必须使用 { mint} 在派生合约中添加供应机制。 * For a generic mechanism see {ERC20PresetMinterPauser}. * 对于通用机制,请参阅 {ERC20PresetMinterPauser}。 * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * 提示:有关详细说明,请参阅我们的指南 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[如何* 实施供应机制]。 * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning false on failure. * * 我们遵循了一般的 OpenZeppelin 合约指南:函数恢复 * 而不是在失败时返回false This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications.尽管如此,这种行为是*传统的,并且与 ERC20 * 应用程序的期望不冲突。 * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * * 此外,在调用 {transferFrom} 时会发出 {Approval} 事件。 * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. * 这允许应用程序通过收听所述事件来重建所有帐户的限额。 Other implementations of the EIP may not emit * these events, as it isn't required by the specification. EIP 的其他实现可能不会发出这些事件,因为规范没有要求。 * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. * * 最后,添加了非标准的 {decreaseAllowance} 和 {increaseAllowance} * 函数,以缓解围绕设置 * 限额的众所周知的问题。 See {IERC20-approve}.请参阅 {IERC20-approve}。 /contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; /contract ERC20 是 Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances;映射(地址 => 映射(地址 => uint256))私有 _allowances; uint256 private _totalSupply; uint256 私人 _totalSupply; string private _name;字符串私有_name; string private _symbol;字符串私有_symbol; / * * @dev Sets the values for {name} and {symbol}. / * * @dev 设置 {name} 和 {symbol} 的值。 * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * {decimals} 的默认值为 18。对于 select,您应该为 * {decimals} 设置不同的值。 * * All two of these values are immutable: they can only be set once during * construction. * * 这两个值都是不可变的:它们只能在构造期间设置一次。 */ constructor(string memory name , string memory symbol_) { name = name ; */ 构造函数(字符串 memory 名称,字符串 memory 符号_){名称=名称 symbol = symbol ;符号=符号 } /** * @dev Returns the name of the token. } /** * @dev 返回令牌的名称。 */ function name() public view virtual override returns (string memory) { return _name; */ function name() public view virtual override returns (string memory) { return _name; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM