Skip to content

Instantly share code, notes, and snippets.

@Y5Yash
Y5Yash / AddressToChecksumString.sol
Created September 25, 2023 07:18
convert address to checksum string (EIP-55) in solidity
function addressToChecksumString(address tempaddr) public view returns (string memory) {
bytes memory lowercase = addressToLowercaseBytes(tempaddr); // get address in lowercase hex without '0x'
bytes32 hashed_addr = keccak256(abi.encodePacked(lowercase)); // get the hash of the lowercase address
bytes memory result = new bytes(42); // store checksum address with '0x' prepended in this.
result[0] = '0';
result[1] = 'x';
uint160 addrValue = uint160(tempaddr);
uint160 hashValue = uint160(bytes20(hashed_addr));