0

I have this code to create hash.

function getUniqueHash(address _hashunique) public view returns (address) 
    {
        bytes20 b = bytes20(keccak256(msg.sender, block.timestamp));
        uint addr = 0;
        for (uint index = b.length-1; index+1 > 0; index--) {
            addr += uint(b[index]) * ( 16 ** ((b.length - index - 1) * 2));
        }
        return address(addr);
    }

But I do not want to give me only one, but to give me a list of hashes when requested by the user.

For example, user asks for 1000 hashes, he has to give me 1000 unique and different hashes, and assign an ID to that batch of 1000 hashes.

  • Not understood properly. Do you want smart contract to return 1000 unique hashes and batch them in one group in a single function call? or user needs to call the function 1000 times to get 1000 unique hashes and go on adding new hash into the batch in each call? – biplavo Jul 25 at 4:13
  • yes, it says that smart contracts return 1000 unique hashes and group them into a single group in a single function call, but add a limit range for example 1000 – Alexis Leonardo Hernandez Soto Jul 25 at 15:33
  • and what is that parameter _hashunique for? Will it be same for 1000 unique hashes generated inside the contract? – biplavo Jul 25 at 16:10
  • i was wrong. function getUniqueHash() public view returns (address) { bytes20 b = bytes20(keccak256(msg.sender, block.timestamp)); uint addr = 0; for (uint index = b.length-1; index+1 > 0; index--) { addr += uint(b[index]) * ( 16 ** ((b.length - index - 1) * 2)); } return address(addr); } – Alexis Leonardo Hernandez Soto Jul 25 at 16:26
  • I am a rookie and just surrender to smart contracts and solidity – Alexis Leonardo Hernandez Soto Jul 25 at 16:51

Your Answer

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

Browse other questions tagged or ask your own question.