Reputation: 852
I would like to know how I can convert a uint256 data type to address on Solidity latest versions.
Here's an example of the code that I'm developing.
function setDetails(string memory _name) public onlyAuthCaller returns(address){
uint256 tmpData = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp)));
address batchNo = address(tmpData);
detailsData.name = _name;
batchDetails[batchNo] = detailsData;
nextAction[batchNo] = 'NEXT';
return batchNo;
}
On Remix, I'm having a TypeError: Explicit type conversion not allowed from "uint256" to "address" on line: address batchNo = address(tmpData);
If someone could help me solve this error for casting these data types.
Regards
Upvotes: 5
Views: 9294
Reputation: 1336
Might be because uint256 is too large, and needs to be truncated.
Taken from the docs:
Upvotes: 6