question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Link an address to a contract as a library in deployer

See original GitHub issue
  • I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

My contract has a libary Lib {} in it. I would like to use an existing library in the migrations script.

Something like:

deployer.linkAddressAsLibrary('0xabcde...', 'AnExistingLibraryOnChain')

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
haltman-atcommented, Feb 17, 2022

Hey, I just had an idea for how to handle this. (Which I am realizing now was implcitly suggested by @ayusht11 above, but we don’t seem to have taken much notice of it at the time, presumably because it wasn’t given as an explicit suggestion.)

We could handle this by allowing the first argument of link to be a library instance rather than a library class. Then you could do await library = Library.at(address); deployer.link(library, Contract). That seems like it would be a fairly natural extension of the current syntax. What do people think of that?

2reactions
bwheeler96commented, Feb 27, 2020

@gnidan This actually already works, the key is that .link returns a thenable, so it must be awaited. Here is what works for me

await MyContract.link('CustomLibraryName', '0xabcde...')

Alternatively you could use .then() syntax.

Also, it should be noted that my deploy script must be setup like this for async to work:

async function doDeploy() {
  await ...
}

module.exports = (deployer, network) => {
  deployer.then(async () => {
    await doDeploy(deployer, network)
  })
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

remix - How to deploy Library contract separate from the main ...
[Q] Is there any way to first deploy the library contract separately from the main contract and than link it to the main...
Read more >
Compile a contract using linked libraries - OpenZeppelin Forum
I see a lot of example of library linking for the deployment. But the contract aspect is not clear. pragma solidity 0.8.15; import...
Read more >
How can I link library and contract in one file? - Stack Overflow
In this case, you have to deploy the library and then need to specify a link for the library in contract deployment.
Read more >
Deploying with Libraries on Remix-IDE - Medium
Click on Deploy. And you have deployed a contract linked to a library! Under the Hood. Let's see where the library's address gets...
Read more >
Libraries in Solidity smart contracts - Crypto Market Pool
Deploy library contract to a test network; Configure Remix with deployed library address; Deploy calling contract. Before we start linking contracts the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found