Sharing an event between a contract and a library

by Ismael   Last Updated June 30, 2020 03:28 AM - source

I've a contract that uses an event and I want to share it with a library without having a duplicated definition.

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

  1. 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?

Tags : solidity


Related Questions


How to map an address with a string array in solidity?

Updated October 09, 2018 12:28 PM

How to handle dynamic size string array in solidity?

Updated November 28, 2018 04:28 AM

What is the status of forbidden call in constructor?

Updated December 12, 2018 08:28 AM

How can I pass struct from one contract to another?

Updated January 10, 2019 23:28 PM

How to transfer Ether to ERC20 token contract?

Updated July 23, 2018 00:28 AM