Abi.encode VS abi.encodePacked

Hi @bb_terk,

See the Solidity documentation for 0.5 breaking changes for the difference between abi.encode and abi.encodePacked

The ABI encoder now properly pads byte arrays and strings from calldata (msg.data and external function parameters) when used in external function calls and in abi.encode. For unpadded encoding, use abi.encodePacked.

abi.encodePacked is a non-standard packed mode

Through abi.encodePacked() , Solidity supports a non-standard packed mode where:

  • types shorter than 32 bytes are neither zero padded nor sign extended and
  • dynamic types are encoded in-place and without the length.
  • array elements are padded, but still encoded in-place

Furthermore, structs as well as nested arrays are not supported.

I am not sure why the tutorial they give uses a mix of abi.encode and abi.encodePacked rather than just using abi.encode


You could look at OpenZeppelin Contracts ECDSA to verify signed messages.

5 Likes