【问题标题】:truffle compile Warning: Invoking events without "emit" prefix is deprecatedtruffle compile 警告:不推荐调用没有“emit”前缀的事件
【发布时间】:2018-04-10 12:08:04
【问题描述】:

truffle 编译输出警告:不推荐调用不带“emit”前缀的事件。

Compilation warnings encountered:

zeppelin-solidity/contracts/token/ERC20/BasicToken.sol:38:5: Warning: 
Invoking events without "emit" prefix is deprecated.
   Transfer(msg.sender, _to, _value);

【问题讨论】:

    标签: ethereum solidity truffle


    【解决方案1】:

    修复方法是删除 zeppelin-solidity 并重新安装版本 zeppelin-solidity 1.8.0

    npm install --save zeppelin-solidity@1.8.0
    

    【讨论】:

      【解决方案2】:

      这与 pragma solidity; 版本有关。从 ^0.4.21 开始,如果事件没有显式使用“emit”关键字调用,编译器将发出警告。

      【讨论】:

      • 知道这意味着什么吗?如果我使用发射会更安全吗?我如何使用发射?提前致谢!
      • 您应该将 "pragma solidity version ^0.4.18" 设置为您的 .sol 文件。警告来自您使用不使用“发射”事件的导入和在发射不存在时发出警告的编译器版本。
      【解决方案3】:

      我尝试更新....但无济于事:

      ~/D/S/z/h/MyToken ❯❯❯ npm install --save zeppelin-solidity@1.8.0
      
      
      + zeppelin-solidity@1.8.0
      updated 1 package in 2.197s
      [tom@13inch.local:~/Dropbox/Sites/zld.awaken.guru/hackernoon/MyToken]
      ~/D/S/z/h/MyToken ❯❯❯ truffle develop
      
      Truffle Develop started at http://127.0.0.1:9545/
      ...
      truffle(develop)> test
      Compiling ./contracts/Migrations.sol...
      Compiling ./contracts/NuZilan.sol...
      Compiling zeppelin-solidity/contracts/math/SafeMath.sol...
      
      Compilation warnings encountered:
      
      /Users/tom/Dropbox/Sites/zld.awaken.guru/hackernoon/MyToken/contracts/NuZilan.sol:64:9: Warning: Invoking events without "emit" prefix is deprecated.
              Transfer(address(0), msg.sender, totalSupply);
              ^-------------------------------------------^
      

      这是一个新的初始化项目(今天),包看起来像:

      {
        "name": "MyToken",
        "version": "1.0.0",
        "description": "",
        "main": "truffle-config.js",
        "directories": {
          "test": "test"
        },
        "scripts": {
          "test": "echo \"Error: no test specified\" && exit 1"
        },
        "keywords": [],
        "author": "",
        "license": "ISC",
        "dependencies": {
          "ethereumjs-tx": "^1.3.4",
          "zeppelin-solidity": "^1.8.0"
        }
      }
      

      【讨论】:

        【解决方案4】:

        emit Transfer(msg.sender, _to, _value); 这应该可以。

        【讨论】:

          猜你喜欢
          • 2018-09-05
          • 1970-01-01
          • 2020-01-31
          • 2021-02-26
          • 2018-03-27
          • 1970-01-01
          • 2020-05-14
          • 1970-01-01
          • 2020-02-23
          相关资源
          最近更新 更多