I see a number of things in Ethereum start with 0x, for example addresses. Other examples are in the Geth console, JSON-RPC, web3.js. What is the 0x and what is its purpose?


1 Answer 1


The "0x" prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex).

For example, the (decimal) number 18 is "12" in hex. To eliminate possible confusion against the number 12, adding 0x at the start makes it clear that 0x12 is hex.

Hex is less human-friendly in some ways, but helps in other ways, for example hex is a shorter way of expressing large numbers.

The Ethereum address you have is just a number, but "behind" it you have a private key so that only you can spend your ether. Contracts each have an address too. They can all be converted to decimal numbers, try it and you'll see that the decimal numbers are much longer: imagine how much harder it would be to look at blockchain explorers if they were using decimal numbers instead of hex.

So the purpose of the 0x is primarily to tell programs that the input is hex. But 0x can also tell humans that what they are reading is hex. Since addresses and transaction hashes are displayed in hex, blockchain explorers could put 0x everywhere to make it clearer that they are hex. But since regular users don't really need to know if an address is hex or not, the explorers omit them in their UIs. For API results however, the use of 0x may be required: when Geth returns your balance as 0x12, that's to make it clear that your balance is actually 18 wei.

One more note: Some data, like balance, may make more sense as a decimal number, so whenever it is presented as hex, the 0x should absolutely be used. But data such as transaction hashes and addresses, make little sense to be provided as a decimal number. Since the only practical way to provide them is in hex, you can omit the 0x. For example, try providing a transaction hash with and without the 0x, to the eth.getTransaction API in Geth and you will get the same results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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