Suppose I have the following Contracts and a Library:

pragma solidity ^0.4.21;

library UserLib {
  function insertUser(address dbAddr, bytes32 user) public {

contract DB {
  mapping(bytes32 => bool) private user;

  function setUser(bytes32 usr) public {
      user[usr] = true;

  function isUser(bytes32 usr) public view returns (bool) {
     return user[usr];

contract Parent {
   using UserLib for *;

   function insertUser(address db, bytes32 usr) public {
      UserLib.insertUser(db, usr);

If I call Parent.insertUser(DB_ADDRESS, "wilco") Remix would output the following:

enter image description here

Notice that it says "Transaction mined but failed" but when I try to change UserLib.insertUser()'s visibility to internal everything works just fine.

I'm trying to move logic into Libraries as other resources says I should do to reduce gas cost upon deploying a contract... what do you think am I missing here?

I'm a newbie to solidity :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.