【问题标题】:Solidity Syntax error - SENTSolidity 语法错误 - SENT
【发布时间】:2018-08-05 00:06:05
【问题描述】:

我正在从官方文档中学习 Solidity,并在我创建简单硬币的练习中堆叠:

pragma solidity ^0.4.20; // should actually be 0.4.21

   contract Coin {
    // The keyword "public" makes those variables
    // readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react on
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    function Coin() public {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) public {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) public {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
}

当我尝试编译时,最后一行出现语法错误: emit Sent(msg.sender, receiver, amount);

我尝试在 Remix 和 VS Code 中编译它,但得到了相同的错误消息。

有人可以帮我吗?

【问题讨论】:

    标签: solidity


    【解决方案1】:

    emit 关键字是在 Solidity 0.4.21 中添加的。在该版本之前,您只使用事件名称来发出事件。

    Sent(msg.sender, receiver, amount);

    您可以查看提案here

    【讨论】:

      猜你喜欢
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多