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.

  • if you look in the linked thread, it's exactly how a library should be called
    – J4D0
    Commented Aug 14, 2020 at 7:42

1 Answer 1


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


  • You wouldn't have to declare it view or pure, if you FourSix and Seven were libraries instead of an abstract contract. The problem here is that the compiler generates call instead of delegatecall to the address (because it doesn't know that it's calling a library.) And because of call protection, the call will revert. I would say that this is an incorrect usage of libraries.
    – hrkrshnn
    Commented Jan 30, 2021 at 14:32

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.