3

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?

1

1 Answer 1

1

Currently it is possible only by editing ABI manually or edit source code with events definitions and rebuild ABI. Github request for change: https://github.com/ethereum/solidity/issues/9765#issuecomment-689396725

Your Answer

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

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