0

I have a library contract deployed on ropsten with address 0xc0b843678E1E73c090De725Ee1Af6a9F728E2C47 and code

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

library customLib {
    address constant owner = 0x8ec42d4D2CbAd10FfD90Ef8033AadFf3d25fbafB;

    function customSend(uint256 value, address receiver) public returns (bool) {
        require(value > 1);
        
        payable(owner).transfer(1);
        
        (bool success,) = payable(receiver).call{value: value-1}("");
        return success;
    }
}

Whenever my contract tries to make payment to an account, it should use the library’s “customSend” function. My contract should be linked to and use the deployed instance of the library; I should not deploy my own instance of the library alongside my contract, nor copy/paste its code in my contract.

contract A {
 function send(address _to, uint256 _amount) external returns(bool) {
  // some code here
  // call customSend function of customLib
}
}

Can somebody pl explain the procedure.

1
  • @goodvibration - Can you pl help Nov 18, 2021 at 17:22

1 Answer 1

0

You could import it and use it with the deployment address like so:

import 'customLib';//Make sure to use the wrigth path

contract A {

 customLib library;

 constructor(address _customLib){
   library = customLib(_customLib);
 }
  function send(address _to, uint256 _amount) external returns(bool) {
   // some code here
   library.customSend(_amount, _to);
 }
}

When deploying the contract just send 0xc0b843678E1E73c090De725Ee1Af6a9F728E2C47 on the constructor since thats the deployment address of the library

2
  • But I do not have the code of customLib, how will I import it ? Or do have to go to the contract address, copy the code and then import the file from a local file structure? Then , what is the use of deploying the library to an address, I could inherit it as any other contract! Nov 20, 2021 at 15:32
  • You will need either the code or the github link of the code for the library to be imported, not necesarrily the address of the deployment. The difference between library and a contract is that a library that doesn't have any storage and cannot hold ether.
    – Julissa DC
    Nov 20, 2021 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.