What is the (a) technical difference between and (b) practical difference between these, i.e., when do you use one or the other:

bool result = address(contract).call.value(10)(bytes4(keccak256("buyItem(uint256)", _sku)));

bool result = address(contract).call.value(10)(abi.encodeWithSignature("buyItem(uint256)", _sku));

The code refers to an exercise where we buy an inventory item, identified by _sku (a uint) for an amount value aka msg.value Thanks

| improve this question | | | | |

as per solidity documentation here

keccak256() now accept only a single bytes argument. Moreover, the argument is not padded. This was changed to make more explicit and clear how the arguments are concatenated.

Change every keccak256(a, b, c) to keccak256(abi.encodePacked(a, b, c)).

Even though it is not a breaking change, it is suggested that developers change x.call(bytes4(keccak256("f(uint256)"), a, b) to x.call(abi.encodeWithSignature("f(uint256)", a, b)).

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.