I wrote a small contract that is supposed to generate an address
from a given publicKey
.
pragma solidity ^0.8.0;
contract GenerateAddress {
bytes public publicKey = "6d7bac197da6e91f506db699a1844efc93b9bf5508bacb6870a98fc2137c4330741f94af61aa635a44f9059ff2082737d43cfb376124ae8772250b85f656aa1d";
function generateAddress() public view returns (address addr) {
bytes32 publicKeyHash = keccak256(publicKey);
addr = address(bytes20(publicKeyHash));
return addr;
}
}
The public key in question was generated from this page: Ethereum Address Generator (Been using it for years to get some test addresses etc.)
So I hard-coded the publicKey
I got from there to test my simple contract.
However the address I got is 0x70191eCc889463533ea48C3A666e7eE0692a0087
while the Ethereum Address Generator
returns 0xdf92c554c0078eec90937d7a5944976ef31d602c
as valid address (For the same public key)
Basically, I get different address
for identical publicKey
and I would like to understand what am I doing wrong.