Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.4 KB

ABI Encoding-Decoding.md

File metadata and controls

40 lines (30 loc) · 1.4 KB

ABI Encoding and Decoding Functions:

  1. abi.decode(bytes memory encodedData, (...)) returns (...): ABI-decodes the given data, while the types are given in parentheses as second argument.

  2. abi.encode(...) returns (bytes memory): ABI-encodes the given arguments

  3. abi.encodePacked(...) returns (bytes memory): Performs packed encoding of the given arguments. Note that packed encoding can be ambiguous!

  4. abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory): ABI-encodes the given arguments starting from the second and prepends the given four-byte selector

  5. abi.encodeWithSignature(string memory signature, ...) returns (bytes memory): Equivalent to abi.encodeWithSelector(bytes4(keccak256(bytes(signature))), …)


Slide Screenshot

077.jpg


Slide Deck

  • abi.encode(...)
  • abi.decode(...)
  • abi.encodeWithSelector(...)
  • abi.decodeWithSignature(...)
  • abi.encodePacked(...)
  • Packed Encoding -> Ambiguous

References


Code Examples

addr.call(abi.encodeWithSignature("transfer(address,uint256)", 0xSomeAddress, 123))
bytes4 selector = bytes4(keccak256("someFunc(address,uint256)"));
abi.encodeWithSelector(selector, _param1, _param2)