Search code examples
ethereumsoliditysmartcontracts

Solidity: get hash number from string;


Is it possible somehow to get a uint256 hash from solidity array types such a strings or bytes32[]?

I want to create mapping (uint256 => address) where uint256 is a hash of some string what user entered earlier. Thanx!


Solution

  • You can use keccak256() on any Solidity type (including strings and arrays) to generate a bytes32 hash. From there, you can either just use the bytes32 result as your key or cast it to a uint.

    Solidity documentation on keccak