1

I am trying to understand libraries and I keep running in to "not found or visible after argument-dependent lookup in type".

pragma solidity ^0.4.17;

library L{
    struct S{
        uint UI;
    }

    function GetLF(S storage R)external returns(uint LOutP) {
        return R.UI;
    }

    function SetLF(S storage R,uint LInP)external {
        R.UI=LInP;
    }
}

contract C{
    using L for L.S;
    L.S LS;

    function setCF(uint CInP)external {
        L.SetLF(LS,CInP); //<-------error
    }

    function GetCF() external returns(uint COutP){
        return L.GetLF(LS); //<-------error 
    }
}

it always happens when trying to use a library function in a contract.

I am thinking it might be a problem with remix because I encountered it with this code. http://solidity.readthedocs.io/en/develop/contracts.html#libraries

pragma solidity ^0.4.11;

library Set {
  struct Data { mapping(uint => bool) flags; }

  function insert (Data storage self, uint value)external
      returns (bool)
  {
      if (self.flags[value])
          return false;
      self.flags[value] = true;
      return true;
  }

  function remove(Data storage self, uint value)external
      returns (bool)
  {
      if (!self.flags[value])
          return false;
      self.flags[value] = false;
      return true;
  }

  function contains(Data storage self, uint value)external
      returns (bool)
  {
      return self.flags[value];
  }
}


contract C {
    Set.Data knownValues;

    function register(uint value)external {
        require(Set.insert(knownValues, value));//<-----error
    }
}

so I am looking to understand cause of this error and understand library keyword better.

I suspect because they lower the one time deployment cost but add to the many time gas operating cost. that they are mostly just for factory pattern type stuff where deployment becomes a many time cost.

0

You firstly have to change the library functions to not be external as library calls are internal to the contract using them. Mark them as public orinternal` instead.

Also there is a more intuitive (at least for me) syntax for the library function calls so instead of

L.SetLF(LS,CInP);

you can do

LS.SetLF(CInP);

  • Wow thanks a lot, so library can never have external or private functions they should make this a error. so the compiler automatically knows to put the LS in to the first storage parameter when dealing with library. thank you this will be helpful in understanding others. – AlexanderLife Oct 24 '17 at 21:47

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.