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
- I embedded
using-for
command inB
. - I deployed
Alireza
and got its address. - I tried to deploy
B
to create its bytecode. As one expects, the deplyoment failed. - I embedded
Alireza
's address toB
's bytecode. Because, as i searched, it is a way to link. - 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:
I tried to embed the hash of
Alireza
's title or directory toB
's bytecode. Just like:--$12b85d948918b1e5773c9bc099694fc73b$--
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.