Welcome to the thread about Events in Ethereum. Here you can discuss everything about this chapter.
just a little observation: in Filip example, in Logs the “1” is not the dog’s age but its id
I am trying hard but i m don t have Events clear yet. I will keep trying🤦‍♂️
I don’t quite get events. I just watched the example by Filip and I don’t see the use
of adding " addres owner, string animalName" as parameters
in the event. I erased them and example works the same. Can you
do something with this parameters ?
Yes, you could listen to those events in javascript front end code for example. So you could get notified whenever person X or address X registers a new pet. Without the parameters that won’t be possible. But you could emit the event without the parameters as well, it’s just not as useful.
Let me know if you need further explanation.
I think I am understanding events. I put an event in the dog contract, when sender is
refunded extra amount of ether. Here it is.
pragma solidity ^0.5.1;
import "./Animal.sol";
contract DogPayableMappingContract is AnimalMappingContract{
event amountRefunded(uint);
modifier costs(uint amount){
require(msg.value>=amount, "Dog not added, unsuficients funds");
_;
if(msg.value> amount){
msg.sender.transfer(msg.value - amount);
emit amountRefunded(msg.value-amount);
}
}
function addDog(string memory _name, uint _age) public payable costs(100) {
require(_age>0, "Dog's age must be >0");
_addAnimal(_name, _age, AnimalType.DOG);
}
function getBalance() public view returns(uint){
return address(this).balance;
}
function getBalanceSender() public view returns(uint){
return msg.sender.balance;
}
}
Thanks