0

I've learned how to use libaries when I've got access to the source code for the library and can therefore import it like this:

import "contracts/MyLibrary.sol";

contract TestMyLibrary {
    using MyLibrary for string;
    ...
}

However I had a look at the "Learneth" addin on Remix, and it seems to suggest its possible to use a library if you know its address, even if you don't have access to the source code but it did not really give a demo on how to do it. I have the impression that its possible to use something like this with access to the source:

  MyLibrary myLibrary = MyLibrary([contract address])

By I haven't been able to get that to work properly. Is there a mechanism to use libraries if you don't have access to the source?

1 Answer 1

1

The question is how to use a deployed contract or library, right?

First you have to know their contract address, And then you have to know what functions it has, which is really easy if it provides a contract interface

If the contract does not provide an interface, then you need to define the interface according to the contract function in order to use it.

And then you use it like this, like you say MyInterface interface = MyInterface(Contract address)

Note that it doesn't have [], then you can use the function in the contract, interface.functionname ()...

If a problem occurs, check whether the contract address is correct and whether the interface function is correct.

May God bless you!😎

1
  • Thanks, I guess it was just the brackets!
    – GGizmos
    Commented Aug 9, 2021 at 5:58

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.