4

I'm learning Solidity from official documentation and stack on an exercise where I create simple coin:

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);
    }
}

When i try to compile i got a syntax error on the last line: emit Sent(msg.sender, receiver, amount);

I tried to compile it in Remix and VS Code but got the same error message.

Can somebody help me pls?

1 Answer 1

2

The emit keyword was added in Solidity 0.4.21. Prior to that version, you emit events by using just the event name.

Sent(msg.sender, receiver, amount);

You can view the proposal here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.