EDIT: I had omitted some data from my code as I thought it was not the one causing the error turns out I was wrong. Here is the question with the appropriate data and solution.

..... Ignore the text below and go to the other question or to the answer below .....

Event not returning child contract address when decoded.

This is the contract that emits the event.

contract ChildFactory {
    event ChildCreated( address child );
    function createChild() external {
        Child child = new Child();
        emit ChildCreated(address(child));

I am trying to decode this event(ethers.utils.defaultAbiCoder.decode(["address"], log.data);) in ehtersjs and I get this error:

Exception: null: value out of range (argument="value", value=20, code=INVALID_ARGUMENT, version=bytes/5.4.0

Why am I getting this error and how can I solve it?


If I omit the address cast on the child contract as suggested in the comments I get this error:

TypeError: Invalid type for argument in function call. Invalid implicit conversion from contract to address requested.

  • try omitting the address cast on the child contract and emitting it directly in the event. Jul 19 at 14:25
  • @KakiMasterOfTime I get an error. I have updated the question with the details.
    – YulePale
    Jul 19 at 14:35
  • The address cast is fine, the error is in the decoding I think. Need more details on that for more clarity on the problem. If you want a solution to the problem, may be you can index the event parameter for easier retrieval
    – shonjs
    Jul 19 at 14:43
  • @shonjs Let me try the solution you have suggested, then I'll get back to you.
    – YulePale
    Jul 19 at 15:09
  • @YulePale so the casting is fine, be sure that you are decoding the log data of that exact event, since this error comes out generally when you are trying to decode a type variable when there is no variable with that type in the encoded bytes. Jul 19 at 15:31