According to the documentation If a library has only internal functions then the library is included in the contract that uses it. There is no need to deploy a separate contract for the library. But I a have public function in a library that's deploying automatically with the contract. But it supposed to be deployed separately cause I was accessing a public function.

Here is my code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;

library math{
    function max(uint x, uint y) public pure returns (uint)
            return x >= y ? x : y;

contract test{
    function testMax(uint x,uint y) external pure returns (uint) {
        return math.max(x,y);

Here I can access the max function without deploying the math library. What's the reason behind it? Note: I am using remix IDE

  • Perhaps the compiler is smart enough to inline your library code Oct 1, 2022 at 12:10
  • I use remix IDE @tsknakamura Oct 1, 2022 at 12:16

1 Answer 1


This comes down to the compiler that you use. Remix IDE will deploy libraries automatically according to the docs - see here.

There is an autoDeployLib attribute in the artifact JSON file of the calling contract. You can set that to false if you'd like to disable this behaviour for a particular contract/library pair. The docs I linked also explain this.

There is also a very similar question I found that might help Why can I use Linked Libraries on Remix IDE without deploying them first?

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.