Cannot use Self before Self has been defined

Hello,

I am trying to reference the treasury account of OpenFPL for topping up the cycles wallet but I have the following error:

So on footballgod (another app I use) I do the same thing but have no problem referencing Self.

Any help greatly appreciated, here is the link to the file:

I believe the problem is that the actor is invoking setCheckCyclesWalletTimer as part of its initialisation code (line 419), which passes the function checkCanisterWalletBalance to Timer.setTimer. That function, however, when called, ultimately ends up trying to call getTreasuryAccount, which needs Self. And Motoko cannot know what Timer.setTimer is doing with the function it’s given, conservatively it must assume that it might try to call it right away, which would hit the incompletely initialised Self.

So you’ll need to stage the initialisation of the timer somehow to resolve this.

1 Like

You are a legend.

Yeah I just need to initialise that through a function, I really appreciate the assist.