https://solidity.readthedocs.io/en/develop/abi-spec.html
>"address: equivalent to uint160, except for the assumed interpretation and language typing. For computing the function selector, address is used."
So I understand from the above document, ethereum addresses are numbers. Is there any way to see or find the number to an ethereum address? And is there any way to send this number through a function to find the corresponding address?
If not, is there any way to look up an address' last signed message and get data from there simply by quering an address?
May 5, 2022, 12:30 PM
Andrey, all addresses are just hex encodeed ints.
So you can convert the string of the address to an int by using a hex converter
May 5, 2022, 12:31 PM
This is my homework... I need convert this uint160 address type 0x***
Idk how..
May 5, 2022, 12:33 PM
what tools can you use? Can you use ethers.js? or inw hat programming langauage?
May 5, 2022, 12:34 PM
Solidity 0.6.6
I have just entered college and am still quite a beginner =((
May 5, 2022, 12:36 PM
well, solidity has less tools and coverting a long hex string means its a wide bit number, in case of address: no normal int types can use it. In solidity you have up to uint256 which do handle that
but manually you can do it with bit shifts
so if it is a school thing, they will want you to understand the nature of bit shifting most likely
and wide number handling
function uint2hexstr(uint i) internal pure returns (string) {
if (i == 0) return "0";
uint j = i;
uint length;
while (j != 0) {
length++;
j = j >> 4;
}
uint mask = 15;
bytes memory bstr = new bytes(length);
uint k = length - 1;
uint numStart = 48;
uint letterStarn = 65;
while (i != 0){
uint curr = (i & mask);
bstr[k--] = curr > 9 ? byte(55 + curr ) : byte(48 + curr); // 55 = 65 - 10
i = i >> 4;
}
return string(bstr);
}
if (i == 0) return "0";
uint j = i;
uint length;
while (j != 0) {
length++;
j = j >> 4;
}
uint mask = 15;
bytes memory bstr = new bytes(length);
uint k = length - 1;
uint numStart = 48;
uint letterStarn = 65;
while (i != 0){
uint curr = (i & mask);
bstr[k--] = curr > 9 ? byte(55 + curr ) : byte(48 + curr); // 55 = 65 - 10
i = i >> 4;
}
return string(bstr);
}
May 5, 2022, 12:40 PM
Yes! I have to do it manually. But I don't know how to do it.
May 5, 2022, 12:40 PM
look at that function, i think it will do the tryick
May 5, 2022, 12:40 PM
Thanks 🙂 I try it
May 5, 2022, 12:41 PM