So, I'm looking into using libraries in order to prevent re-deployment/re-use of the same code.

I was hoping that I would be able to specify the address of a library in solidity code, using syntax along the lines of

using SomeDeployedLib at 0x1234;

but this doesn't appear to be a possibility yet. Libraries are instead swapped into the generated bytecode by the linker, initially appearing as a placeholder.

So, in which environments can I easily insert the address of an existing library and avoid deploying it again?

Solc command line allows me to do this with something like

solc --optimize --bin MyContract.sol | solc --link --libraries SomeDeployedLib:<address>

so this is one option, but it isn't eactly the most user-friendly of environments to work with.

The Remix IDE supports libraries, but as far as I can tell appears to offer no option to link libraries via an existing address, and instead deploys copies of them every time with your new contract. Not efficient, and not what I'm after.

Parity has a nice UI, but again no option to specify the address of existing libraries, everything is deployed in one go.

Are there any other options?

  • my understanding is that the library needs to be included with the launcher contract so everytime a contract is getting created it reference the library and keep the costs low. – Arash Kiani Jul 12 '18 at 15:43
  • I think if you're going to be allowed to change the library at any point then perhaps your program is not decentralised anymore. – Arash Kiani Jul 12 '18 at 15:44
  • also maybe to include you need Interface with the actual contract – Arash Kiani Jul 12 '18 at 15:45
  • 1
    I am not suggesting the library needs to be able to be changed. I'm saying that as far as I can tell, only solc allows me to link to an existing library address rather than deploy the same library code again every time I publish a contract – AndyK Aug 2 '18 at 16:27
  • I was looking for such a solution for a long time but i couldn't find, so i convinced myself with the answer I gave you earlier, to be fair I would love to know if such solution exist. i agree its very frustrating to link to same library everytime you deploy – Arash Kiani Aug 2 '18 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.