0

My understanding is that if a smart contract consumes a library that only has internal functions, then the compiler will embed the library into the contract bytecode. At the lowest level, there is no use of DELEGATECALL - a call to an internal function of a library is a simple JUMP statement.

Conversely, if the library does have public/ external functions, the library has to be deployed separately.

At first glance, it seems that most libraries only contain internal functions:

What are the best use cases for a linked library?

2
  • Probably common state for several contracts. Jul 8, 2020 at 11:02
  • 1
    A few years ago we had a large contract that didn't fit the block gas limit at the time (6M gas), so we used libraries to split it into smaller pieces that we were able to deploy. It should have deployed perfectly fine with the current block gas limit of 12M though.
    – Ismael
    Jul 8, 2020 at 20:48

1 Answer 1

2

Reusability, see sentence one here.

Libraries are similar to contracts, but their purpose is that they are deployed only once at a specific address and their code is reused using the DELEGATECALL.

Although honestly the use of reusable libraries hasn't really taken off, there is at least one project aiming to provide those: https://github.com/modular-network/ethereum-libraries.

Otherwise, external libraries can also help staying below the contract size limit.

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.