ABI Encoding and Decoding Functions:
-
abi.decode(bytes memory encodedData, (...)) returns (...)
: ABI-decodes the given data, while the types are given in parentheses as second argument. -
abi.encode(...)
returns (bytes memory): ABI-encodes the given arguments -
abi.encodePacked(...)
returns (bytes memory): Performs packed encoding of the given arguments. Note that packed encoding can be ambiguous! -
abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory)
: ABI-encodes the given arguments starting from the second and prepends the given four-byte selector -
abi.encodeWithSignature(string memory signature, ...) returns (bytes memory)
: Equivalent to abi.encodeWithSelector(bytes4(keccak256(bytes(signature))), …)
abi.encode(...)
abi.decode(...)
abi.encodeWithSelector(...)
abi.decodeWithSignature(...)
abi.encodePacked(...)
- Packed Encoding -> Ambiguous
addr.call(abi.encodeWithSignature("transfer(address,uint256)", 0xSomeAddress, 123))
bytes4 selector = bytes4(keccak256("someFunc(address,uint256)"));
abi.encodeWithSelector(selector, _param1, _param2)