README.adoc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. = Utilities
  2. [.readme-notice]
  3. NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/utils
  4. Miscellaneous contracts and libraries containing utility functions you can use to improve security, work with new data types, or safely use low-level primitives.
  5. The {Address}, {Arrays}, {Base64} and {Strings} libraries provide more operations related to these native data types, while {SafeCast} adds ways to safely convert between the different signed and unsigned numeric types.
  6. {Multicall} provides a function to batch together multiple calls in a single external call.
  7. For new data types:
  8. * {EnumerableMap}: like Solidity's https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] type, but with key-value _enumeration_: this will let you know how many entries a mapping has, and iterate over them (which is not possible with `mapping`).
  9. * {EnumerableSet}: like {EnumerableMap}, but for https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets]. Can be used to store privileged accounts, issued IDs, etc.
  10. [NOTE]
  11. ====
  12. Because Solidity does not support generic types, {EnumerableMap} and {EnumerableSet} are specialized to a limited number of key-value types.
  13. As of v3.0, {EnumerableMap} supports `uint256 -> address` (`UintToAddressMap`), and {EnumerableSet} supports `address` and `uint256` (`AddressSet` and `UintSet`).
  14. ====
  15. Finally, {Create2} contains all necessary utilities to safely use the https://blog.openzeppelin.com/getting-the-most-out-of-create2/[`CREATE2` EVM opcode], without having to deal with low-level assembly.
  16. == Math
  17. {{Math}}
  18. {{SignedMath}}
  19. {{SafeCast}}
  20. == Cryptography
  21. {{ECDSA}}
  22. {{MessageHashUtils}}
  23. {{SignatureChecker}}
  24. {{MerkleProof}}
  25. {{EIP712}}
  26. == Introspection
  27. This set of interfaces and contracts deal with https://en.wikipedia.org/wiki/Type_introspection[type introspection] of contracts, that is, examining which functions can be called on them. This is usually referred to as a contract's _interface_.
  28. Ethereum contracts have no native concept of an interface, so applications must usually simply trust they are not making an incorrect call. For trusted setups this is a non-issue, but often unknown and untrusted third-party addresses need to be interacted with. There may even not be any direct calls to them! (e.g. `ERC20` tokens may be sent to a contract that lacks a way to transfer them out of it, locking them forever). In these cases, a contract _declaring_ its interface can be very helpful in preventing errors.
  29. {{IERC165}}
  30. {{ERC165}}
  31. {{ERC165Checker}}
  32. == Data Structures
  33. {{BitMaps}}
  34. {{EnumerableMap}}
  35. {{EnumerableSet}}
  36. {{DoubleEndedQueue}}
  37. {{Checkpoints}}
  38. == Libraries
  39. {{Create2}}
  40. {{Address}}
  41. {{Arrays}}
  42. {{Base64}}
  43. {{Strings}}
  44. {{ShortStrings}}
  45. {{StorageSlot}}
  46. {{Multicall}}