keccak256 in solidity

keccak256 returns hash of the given argument. It receives arguments with the type of bytes (not in the form of fixed bytes e.g bytes1 to bytes32). And returns hash of bytes32.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;

contract _keccak{

    
    function checkkeccak256()public pure returns(bytes32){
        bytes memory bb = 'asxasxs'; 
        return keccak256(bb);
    }
    
        
    function checkkeccak256(string memory name, uint age, address addr)public pure returns(bytes32){
        //encode more than one arguments in keccak with abi.encodePacked
        return keccak256(abi.encodePacked(name,age,addr));
    }
    
        
    function checkkeccak256(string memory name,string memory homeAddress, address addr)public pure returns(bytes32){
        //encode more than one arguments in keccak with abi.encode
        return keccak256(abi.encode(name,homeAddress,addr));
    }
}

By Shabair

Frontend | Blockchain | Smart Contract Developer