Skip to main content
2 of 2
Improve grammar, wording, punctuation.

The expression using Library for type allows us to use a syntactic sugar when using certain functions from the library. It is not required, but it makes the contract more readable.

For example, SafeMath had

library SafeMath {
    function add(uint256 a, uint256 b) public pure returns (uint256) {
        // some unimportant details here
    }
}

Then you could use in a contract

function (uint256 x, uint256 y) public pure returns (uint256) {
    returns add(x, y);
}

You can add using SafeMath for uint256

function (uint256 x, uint256 y) public pure returns (uint256) {
    returns x.add(y);
}

It isn't much per se, but it has a syntax close to calling a method from an object.

Ismael
  • 30.3k
  • 23
  • 54
  • 97