4

Is it possible to watch for event triggers when the actual event and trigger is defined in a library? I get no console output with the following code

library ObjectHistoryLib {

    event SerialObjEvent(
        bytes32 description,
        bytes32 repair,
        uint indexed serialIndex
    );

    function setObj(address _storageContract, uint serialId, bytes32 description, bytes32 repair) {
        SerialObjEvent(description, repair, serialId);
    }
}

I then place a watch on the "SerialObjEvent" using truffle web3 syntax

var histLib = ObjectHistoryLib.deployed();
var objQuery = histLib.SerialObjEvent({}, {fromBlock: 10, toBlock: 'latest' });
objQuery.watch(function (error, result) { console.log(JSON.stringify(result)); });

But I get no output when I call the setObj function

1 Answer 1

3

There is a "hack" or trick for that. The event has to be defined in both the smart contract and in the used library. After doing that, the event should get triggered accordingly.

So you have to add the event

event SerialObjEvent(
   bytes32 description,
   bytes32 repair,
   uint indexed serialIndex
);

in the smart Contract that is calling your library function.

This procedure is also described here: https://web.archive.org/web/20180922101404/https://blog.aragon.org/library-driven-development-in-solidity-2bebcaf88736/ (archived)

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.