3

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?

3
  • see or find the number to an ethereum address - what does that even mean? The address IS a number. Jul 31, 2020 at 7:33
  • 1
    Nik: @goodvibration does not mean to be unfriendly or unkind, so your comment flag will be declined. Addresses are in hexadecimal. For example the number 11 would be "b" in hexadecimal.
    – eth
    Aug 5, 2020 at 17:56

2 Answers 2

3

Is there any way to see or find the number to an ethereum address?

Sure, you're looking at it any time you look at an address... It's just not in base10, so letters are used to fill in for missing numbers that don't exist in base 10 (e.g., 10 is "a" in base-16). You can cast it to different types to get a better look at it. In solidity, you can just do:

uint256(uint160(_addr))

Or, in JS:

console.log(10 == parseInt("a",16), "this is true")
console.log(11 == parseInt("b",16), "this is true")
const publicKey = "0xCA6b8EaB76F76B458b1c43c0C5f500b33f63F475"
const addressInBase10 = parseInt(publicKey,16)

Keep in mind, that number is too big to be precisely shown in JS, so you need a bigInt library (which is included with libs like ethers and web3), or some other solution.

And is there any way to send this number through a function to find the corresponding address?

Sure, you can convert base10 into base16 in JS as well

let x = 10
console.log(x.toString(16) === "a", "this is true");

but again, because of precision limitations, don't expect it to match... if JS could handle the precision, this would be true:

console.log(parseInt("100",16).toString(16) === '100', "this is true, because 100 is within JS's range of possible precision")

publicKey = "0xCA6b8EaB76F76B458b1c43c0C5f500b33f63F475";
console.log(publicKey === parseInt(publicKey,16).toString(16), "this is false, even though it should be true, because JS can't handle numbers this big; instead we get 
ca6b8eab76f76800000000000000000000000000--all those zeroes show us the missing precision pretty clearly");

If not, is there any way to look up an address' last signed message and get data from there simply by quering an address?

Yup, but no number switching needed. Just type the address into https://etherscan.io/

0

ethers.js library includes BigNumber

The following code helped me convert an address to a uint160 without overflowing

import { BigNumber } from "ethers";

BigNumber.from("0xCA6b8EaB76F76B458b1c43c0C5f500b33f63F475").toBigInt().toString(10);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.