Solidity Error – Explicit Type Conversion Not Allowed from ‘Bytes32’ to ‘Address’

solidity-0.5.x

I am using solidity 0.5.0 when i compile code i am throwing exception as
Explicit type conversion not allowed from "bytes32" to "address".

code is working fine in remix IDE

enter image description here

and my code is as

function orderItem(uint _itemid,string memory _itemname ) public returns(address){
    address uniqueId = address(sha256(msg.sender,'block.timestamp'));
    packagemapping[uniqueId].isuidgenerated = true;
    packagemapping[uniqueId].itemid = _itemid;
    packagemapping[uniqueId].itemname = _itemname;
    packagemapping[uniqueId].transactionstatus = " Your package is ordered and is under processing ";
    packagemapping[uniqueId].orderstatus = 1;
    packagemapping[uniqueId].customer = msg.sender;
    packagemapping[uniqueId].ordertime = "block.timestamp";
    return uniqueId;
}

error line: address uniqueId = address(sha256(msg.sender,'block.timestamp'));

Best Answer

address uniqueId = address(bytes20(sha256(abi.encodePacked(msg.sender,'block.timestamp'))));

Also, why 'block.timestamp' is in quotes? Maybe it should be:

address uniqueId = address(bytes20(sha256(abi.encodePacked(msg.sender,block.timestamp))));
Related Topic