1

I'm trying to deploy my library and call it afterwards with the specific address. While testing this I encountered that the behavior changed over the course of compilers.

I tried to follow How to call a library contract but the following inconsistency happened:

Library 1

pragma solidity 0.7.0;

library Seven {
    function seven() public returns (bool) {
        return true;
    }
}

Library 2

pragma solidity 0.4.6;

library Foursix {
    function foursix() public returns (bool) {
        return true;
    }
}

Main Contract

pragma solidity 0.7.0;
abstract contract Foursix {
    function foursix() virtual public returns (bool);
}

abstract contract Seven {
    function seven() virtual public returns (bool);
}

contract Foo {
    function callfoursix(address a) public {
        Foursix fs = Foursix(a);
        bool b = fs.foursix();
    }
    function callseven(address a) public {
        Seven s = Seven(a);
        bool b = s.seven();
    }
}

notice how Library 1 and 2 are identical besides the used compiler. When testing in remix Library 1 gets the error:

transact to Foo.callseven errored: VM error: revert.

while the call to Library 2 succeeds.

Why is this the case and how do I call the Library 1 contract? It does seem that ABI encoding has something to do with it as the newer version is seemingly not found but for the moment I'm clueless.

  • In your main contract you are using abstract contracts, instead of libraries. – hrkrshnn Aug 10 at 17:55
  • if you look in the linked thread, it's exactly how a library should be called – J4D0 Aug 14 at 7:42
0

Turns out functions have to be declared as "view or pure" when called from outside after solidity version 0.5.

https://solidity.readthedocs.io/en/develop/contracts.html#call-protection-for-libraries

| improve this answer | |

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.