toString
Signature
Section titled “Signature”function toString(address) external returns (string memory);function toString(bool) external returns (string memory);function toString(uint256) external returns (string memory);function toString(int256) external returns (string memory);function toString(bytes32) external returns (string memory);function toString(bytes) external returns (string memory);Description
Section titled “Description”Convert any type to its string version. Very useful for operations that demand strings, such as the cheatcode ffi.
Bytes are converted to a string of their hex representation with 0x at the start, signifying that they are encoded in hex.
Examples
Section titled “Examples”uint256 number = 420;string memory stringNumber = vm.toString(number);vm.assertEq(stringNumber, "420");bytes memory testBytes = hex"7109709ECfa91a80626fF3989D68f67F5b1DD12D";string memory stringBytes = cheats.toString(testBytes);assertEq("0x7109709ecfa91a80626ff3989d68f67f5b1dd12d", stringBytes);address testAddress = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;string memory stringAddress = cheats.toString(testAddress);assertEq("0x7109709ECfa91a80626fF3989D68f67F5b1DD12D", stringAddress);