I've a contract that uses an event and I want to share it with a library without having a duplicated definition.
- The event is in the library, and contract uses it from the library. It works but the problem is that the event is not in the contract's ABI. So a testing framework like Truffle will not recognize it as generated by the contract. I can add the event to the abi by hand but it seems 'hackish'.
library Party {
event Pinata(uint candies);
function showPinata() internal {
emit Pinata(123);
}
}
contract Birthday {
function celeb() public {
emit Party.Pinata(222);
}
}
- The event is in the contract an the library uses it. The problem is that it doesn't compile. 'TyperError: Member "Pinata" not found or not visible after argument-dependent lookup'. As a workaround it can be duplicated in the library but it is error prone to have two separate definitions.
library Party {
function showPinata() internal {
emit Birthday.Pinata(222);
}
}
contract Birthday {
event Pinata(uint candies);
function celeb() public {
emit Pinata(123);
}
}
Is there another way to solve this issue without having a duplicated definition of the event or editing the generated ABI?