Solidity REPL
Contracts & calls

Library using-for directive

Attach a library function to uint256 as a member function.

Solidity 0.8.36REPL mode

Why use this example

Use this pattern to test contract composition, external calls, events, and return values inside one reproducible run. The entry isolates library using-for directive so its input, result, and state changes stay easy to compare.

Solidity to run

library UintMath {
  function squared(uint256 self) internal pure returns (uint256) {
    return self * self;
  }
}
contract Calculator {
  using UintMath for uint256;
  function square(uint256 value) external pure returns (uint256) {
    return value.squared();
  }
}

Calculator calculator = new Calculator()
calculator.square(7)

Official Solidity reference

Compare this focused investigation with the complete language definition in the Solidity documentation.

Using for

What to expect

The using-for directive exposes squared as a uint256 member and the contract returns 49.

Continue the investigation

Change a value, add another expression, or open Inspect after the run. Accepted entries remain available to the next entry, and the clean replay keeps the complete result reproducible.

Read about calls and logs Reproducible investigation