3

I have a contract A, which has an instance of contract B, i.e., B b.

Contract A calls a function of contract B via the instance, i.e., b.func().

Contract B is stateless, i.e., no global non-constant variables.

I therefore decided to redeclare it as a library.

After that, when I compile contract A, I get the following error:

TypeError:
Member "func" not found or not visible after argument-dependent lookup in type(library B)

I can resolve the problem by changing the access-level of func from external to internal.

However, that prevents me from calling the function via Web3 (Python).

Can someone please explain this odd behavior, i.e., why do I need to reduce the function's access-level from external to internal after I "reduce" the contract to a library?

UPDATE:

I think I got it:

The library code is "embedded" into the contract which imports it (like a macro in C if you will).

Then, only functions that are either private, internal or public can be invoked from inside the contract, while external functions can be invoked only from outside the contract.

So my question really is:

How can I reconcile the fact that I want these functions to be internal when used by a contract, and external when accessed via Web3 (for testing purpose)?

Thank you!

1
  • I tried reproducing the above error, however, I couldn't, could you share your contract code please? Mar 21, 2020 at 7:10

1 Answer 1

1

Try using internal in the library, then create a public function that proxies to the library, like:

contract A {
  function func() public returns (?) {
    return b.func();
  }
}

Note: I left a ? in the return type descriptor because the return type of b.func() wasn't specified in the question. Fill it in with the type returned by b.func().

1
  • Thought about this, but then - what's the point in having that library to begin with? I might as well just declare it as a contract with a public func (instead of a library and a "proxy" contract). Jan 5, 2018 at 22:25

Your Answer

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

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