Application Binary Interface encoding functions

Solidity provides many global functions to encode (including packed encoding) the different data types of Solidity. This encoded data is used to create payload data that can be sent to function calls for the external contract calls. These are also used to generate unique hashes of different values.

The following are the different functions available:

  • abi.encode(...) returns (bytes): ABI encodes the given arguments. Arguments can be of any type. It returns the encoded data as bytes.
  • abi.encodePacked(...) returns (bytes): This performs packed encoding of the given arguments. Arguments can be of any type. It returns the packed encoding of the data as bytes.
  • abi.encodeWithSelector(bytes4 selector, ...

Get Mastering Blockchain Programming with Solidity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.