6

I need to understand how is it possible to access the calling contract storage from library code. From Solidity manual:

This means that if library functions are called, their code is executed in the context of the calling contract, i.e. this points to the calling contract, and especially the storage from the calling contract can be accessed.

So I'm trying to compile this simple test library:

library Test_Lib {
    function test_function()
    public
    returns (bool)
    {
        return (this.owner.send(this.balance));
    }
}

But I get the following error:

Error: Member "owner" not found or not visible after argument-dependent lookup in library Test_Lib

Where am I wrong?

3

If you think about it, the library can not know the variable names of the calling contract. The compiler must fail. What you can do is pass the variable through the interface. In the background, no transaction calls need to be done and the param can be passed by-reference instead of by-value...

  • 1
    Got it. How would you rewrite it, something like the following? function test_function(address calling_contract) – Sun78 Jul 5 '16 at 14:39
  • at least upvote me ;-) – Roland Kofler Jul 5 '16 at 14:40
  • 1
    Just did it. Sorry I'm new to this site :) – Sun78 Jul 5 '16 at 14:49
  • yes you pass the address – Roland Kofler Jul 5 '16 at 14:51
  • I guess I still do some mistake with the syntax of this: Error: Member "owner" not found or not visible after argument-dependent lookup in address (caller is the argument of the function) return (caller.owner.send(caller.balance)); – Sun78 Jul 5 '16 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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