繁体   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.

当我在默认的本地 ganache-cli 上使用 brownie 进行部署时。

命令:

$ brownie compile

得到:

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.

令牌文件头:

pragma solidity ^0.8.0;

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

contract InvestToken is ERC20 {

布朗尼-config.yaml 文件:

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

命令:

$brownie pm install OpenZeppelin/openzeppelin-contracts@4.4.2

得到:

FileExistsError("Package is aleady installed")

我在 brownie-config.yaml 文件中犯了一个错误:

我写:

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

它是

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

对于那个很抱歉

根据您的错误,我认为与 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}

当我将表单选项卡固定到空格时

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

你也可以查看帕特里克的参考

跳到内容

OpenZeppelin/openzeppelin-contractsPublic

CodeIssues116Pull requests30ActionsSecurity11Insights

掌握

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; 背景颜色:透明; 颜色:var(--color-fg-muted);重要:文本装饰; none:">修复损坏的论坛 URL (#3537" class="Link--secondary" href="https.//github:com/OpenZeppelin/openzeppelin-contracts/commit/5e7e9acfa4630c1f933f7e8435ccc4490cacb274" style="box-sizing;框:背景颜色;透明:颜色;var(--color-fg-muted):重要;文本装饰:无;">)

42 位贡献者+26

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; 导入“./IERC20.sol”;导入“./extensions/IERC20Metadata.sol”;导入“../../utils/Context.sol”; /** * @dev 实现 {IERC20} 接口。 * * 此实现与创建令牌的方式无关。 这意味着 * 必须使用 { mint} 在派生合约中添加供应机制。 * 对于通用机制,请参阅 {ERC20PresetMinterPauser}。 * * 提示:有关详细说明,请参阅我们的指南 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[如何* 实施供应机制]。 * * 我们遵循了一般的 OpenZeppelin 合约指南:函数恢复 * 而不是在失败时返回false 尽管如此,这种行为是*传统的,并且与 ERC20 * 应用程序的期望不冲突。 * * 此外,在调用 {transferFrom} 时会发出 {Approval} 事件。 * 这允许应用程序通过收听所述事件来重建所有帐户的限额。 EIP 的其他实现可能不会发出这些事件,因为规范没有要求。 * * 最后,添加了非标准的 {decreaseAllowance} 和 {increaseAllowance} * 函数,以缓解围绕设置 * 限额的众所周知的问题。 请参阅 {IERC20-approve}。 /contract ERC20 是 Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; 映射(地址 => 映射(地址 => uint256))私有 _allowances; uint256 私人 _totalSupply; 字符串私有_name; 字符串私有_symbol; / * * @dev 设置 {name} 和 {symbol} 的值。 * * {decimals} 的默认值为 18。对于 select,您应该为 * {decimals} 设置不同的值。 * * 这两个值都是不可变的:它们只能在构造期间设置一次。 */ 构造函数(字符串 memory 名称,字符串 memory 符号_){名称=名称 符号=符号 } /** * @dev 返回令牌的名称。 */ 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