21

In this question the OP is running into a warning upon using the keccak256 function in Solidity:

Warning: This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.

uint256 _unixTimestamp;
uint256 _timeExpired;

bytes32 output = keccak256(msg.sender, _unixTimestamp, _timeExpired);

What is the rationale behind this error - why do I need to use abi.encodePacked and what does it do in comparison to using it just like shown above?

SCBuergel
  • 8,774
  • 7
  • 38
  • 69

2 Answers2

24

It means that now you need to change your code to:

uint256 _unixTimestamp;
uint256 _timeExpired;

bytes32 output = keccak256(
  abi.encodePacked(msg.sender, _unixTimestamp, _timeExpired)
);
rstormsf
  • 4,337
  • 2
  • 25
  • 42
8

Prior to Solidity 0.5.0, both functioned the same way. The warning is part of the process of deprecating the variable-argument versions of keccak256 and other hash functions.

As of Solidity 0.5.0, sha3 has been removed. See https://github.com/ethereum/solidity/issues/3955 for details.

user19510
  • 27,999
  • 2
  • 30
  • 48