Me gustaría saber cómo obtener un hash bytes32 keccak256 de una dirección y 2 variables uint256.
Quiero algo que se vea así. Pero a partir de los errores de remix IDE, necesito convertir las 3 variables en bytes32 y luego hacer un hash de eso.
/* here are the variable names and types (Apart from msg.sender which is address */
uint256 _unixTimestamp;
uint256 _timeExpired;
/* This is what I have got so far, what do I need to do to fix the error? */
bytes32 output = keccak256(msg.sender, _unixTimestamp, _timeExpired);
Aquí está el mensaje de advertencia del IDE de remix
Advertencia: esta función solo acepta un único argumento de "bytes". Utilice "abi.encodePacked(...)" o una función similar para codificar los datos.
bytes32 salida = keccak256(msg.sender, _unixTimestamp, _timeExpired);
. . . . . . . . . . . . . .^------------------------------------------------ -------------- ^
Como se informa en este hilo: https://github.com/ethereum/solidity/issues/3955
Los nuevos métodos abi.encode*() ofrecen un reemplazo para realizar el empaquetado, que luego se puede pasar a todas estas funciones hash.
En pocas palabras: como comentó @mirg , solo use abi.encodePacked() dentro de keccak256(). Es decir:
keccak256(abi.encodePacked(msg.sender, _unixTimestamp, _timeExpired))
mirg
uint265
en lugar deuint256
otro que eso debería funcionarBlockchainBoy
mirg
keccak256(abi.encodePacked(msg.sender, _unixTimestamp, _timeExpired))