3

I work in Truffle development environment and use Windows PowerShell. My Solidity code is a test code and is simple. There is a library called Alireza that just compares two uint values. There is a contract called B that just uses the library function to compare two uint values. Now, i need to link Alireza to B. For that

  1. I embedded using-for command in B.
  2. I deployed Alireza and got its address.
  3. I tried to deploy B to create its bytecode. As one expects, the deplyoment failed.
  4. I embedded Alireza's address to B's bytecode. Because, as i searched, it is a way to link.
  5. I tried to deploy B again and it failed again.

Is this work flow correct? i don't know. So, i intent to try another way that here mentioned:

  1. I tried to embed the hash of Alireza's title or directory to B's bytecode. Just like:

     --$12b85d948918b1e5773c9bc099694fc73b$--
    
  2. I tried to deploy B again and again the deployment failed.

Even, before all ways i mentioned, i deployed B without deployment of Alireza before that. Because i thought maybe, by this way, the compiler would create the link. But, the below error emerges:

Error: B contains unresolved libraries. You must deploy and link the following libraries before you can deploy a new version of B: Alireza

Am i in a correct way? Where is my problem? How can i link a library to a contract just by Solidity and contract's bytecode and without node-js? How should i alter my work flow to link?

My whole code:

pragma solidity ^0.5.12;

library Alireza{

    function comparison(uint a, uint b) view public returns(bool){  
        if(a==b){
            return true;
        }else{
            return false;
        }
    }
}

contract B{

    using Alireza for uint;

    function assessment(uint m, uint n) view public returns(bool){
        return m.comparison(n);
    }
}

Thank you.

0

Just compile the code and deploy contract B, no need to do the link thing. The library code will copy to contract B automatically by the compiler.

1
  • I tried that but the followed error emerges: Error: B contains unresolved libraries. You must deploy and link the following libraries before you can deploy a new version of B: Alireza. It says first a library must be deployed before a contract deployment. – Alireza May 11 at 12:17

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.