1

CONTEXT OF THE QUESTION:

The references at the end of this post gave me the following understanding of events:

Whenever a transaction takes place that is meant to alter information in the blockchain, an event is the tool used to do the logging of that information.

Since I am coding my first ERC-20 Standard compatible Token, here is an example of the usage of events:

mapping (address => uint256) public balances;
event Transfer(address indexed from, address indexed to, uint tokens);

function transfer(address to, uint tokens) public returns (bool success) 
{
    balances[msg.sender] = balances[msg.sender].sub(tokens);
    balances[to] = balances[to].add(tokens);
    Transfer(msg.sender, to, tokens);
    return true;
}

The second line declares an event that has 3 input variables, who is sending (from), who is receiving (to), and the amount being sent (tokens). And when the function transfer is involved we see the usage of the event. It makes sense to me that this is where it should be involved, but what I don't understand is how Solidity ties this code:

event Transfer(address indexed from, address indexed to, uint tokens);

with making sure that the balances of users are not faked. The event in my mind must be linking the 3 parameters together into the blockchain, but how does that linking happen? and how does the blockchain then prevent balances from being faked.

DETAILED QUESTIONS:

  • What happens behind the scenes that links the Transfer event with the verification of what the balances are? Please feel free to go into depths

  • If I had used another word, like Foobar and replaced the word Transfer with it, would the code still work? The reason I ask is because it seems like I am defining what Transfer is doing by declaring it (so by default it not being a predefined event of solidity), but I don't seem to be coding in much else.


References:

4

An event is basically a print statement by the contract. Nothing is verified. The contract can log whatever it wants.

What happens behind the scenes that links the Transfer event with the verification of what the balances are? Please feel free to go into depths

Absolutely nothing.

If I had used another word, like Foobar and replaced the word Transfer with it, would the code still work? The reason I ask is because it seems like I am defining what Transfer is doing by declaring it (so by default it not being a predefined event of solidity), but I don't seem to be coding in much else.

Yes, but someone reading the event would see an event called "Foobar" instead.

  • Oh so events have nothing to do with how ethereum enforces byzantine fault tolerance? They are just a type of console.log(...) for practicality purposes? – Webeng Mar 24 '18 at 22:59
  • 1
    That's correct. – user19510 Mar 24 '18 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.