<p>You're hashing the string representation of things, not the actual hash itself. Hash the bytes of the hash, not the bytes of its string representation.</p>

<p>All of the should operations are on the bytes themselves, not the hexadecimal representation of those bytes which is what you have done.</p>

CC BY-SA 4.0
2019-05-15T23:48:50.837Z
Also checksum is calculated _after_ prefixing version byte to rmd160(sha256(pubkey)) not before.
dave_thompson_085
CC BY-SA 4.0
2019-05-16T17:52:14.447Z
@dave_thompson_085 the calculation is the same if you haven't noticed.
Dan shpaner
CC BY-SA 4.0
2019-05-21T06:53:22.407Z
@Danshpaner: I have noticed it is _not_ the same. But go ahead and do whatever you want, it doesn't hurt me a bit.
dave_thompson_085
CC BY-SA 4.0
2019-05-15T22:01:51.797Z
2019-05-15T22:01:51.797Z
Ava Chow
<p>So after searching for HOURS on here and overall on the internet, I haven't managed to find an answer to my question so I'll ask here.</p>

<p>So I've been trying to convert a public key into an address. I've been writing all the hashing algorithms, and tested them with online hashing websites, so they are working. Here is my code:</p>

<pre><code>function getBTCAddress(public_key) 
{
   var __SHA = SHA256_hash(public_key);
   console.log("__SHA: " + __SHA);
   var RIPEMD = RIPEMD_160(__SHA);
   console.log("RIPEMD_160: " + RIPEMD);

   var new_SHA = SHA256_hash(RIPEMD.toString());
   console.log("new_SHA: " + new_SHA);
   var _new_SHA = SHA256_hash(new_SHA);
   console.log("_new_SHA: " + _new_SHA);

   var checksum = _new_SHA.slice(-8, _new_SHA.length);
   console.log("checksum:" + checksum);

   var almost_address = "00" + RIPEMD.toString() + checksum;
   console.log("almost_address:" + almost_address);

   var buffer = Buffer.from(almost_address, "hex");

   return BS58.encode(buffer);

}
</code></pre>

<p>For some reason it is not giving me the proper results. I'm wondering, what are the exact steps of deriving an address from a public key?</p>

<p>For those of your who are wondering here is what my code is doing:</p>

<pre><code>  checksum = SHA256(SHA256(RIPEMD160(SHA256(public_key)))) &lt;-- get last 8 bytes

  almost_address = 0x00 (network byte) and RIPEMD160(SHA256(public_key)) and checksum &lt;-- compacted into 1 string

  address = base58(almost(address)
</code></pre>

CC BY-SA 4.0
2019-05-16T10:27:33.763Z
this any help? https://bitcoin.stackexchange.com/questions/76181/bitcoin-public-keys-from-uncompressed-to-compressed-version-with-code-sample
Fuzzybear
<address><public-key>
Bitcoin Public Key To Address Uncompressed
Dan shpaner
# Bitcoin Public Key To Address Uncompressed

(Asked by: username_0 on 2019-05-15)

So after searching for HOURS on here and overall on the internet, I haven't managed to find an answer to my question so I'll ask here.
So I've been trying to convert a public key into an address. I've been writing all the hashing algorithms, and tested them with online hashing websites, so they are working. Here is my code:
function getBTCAddress(public_key) 
{
   var __SHA = SHA256_hash(public_key);
   console.log("__SHA: " + __SHA);
   var RIPEMD = RIPEMD_160(__SHA);
   console.log("RIPEMD_160: " + RIPEMD);

   var new_SHA = SHA256_hash(RIPEMD.toString());
   console.log("new_SHA: " + new_SHA);
   var _new_SHA = SHA256_hash(new_SHA);
   console.log("_new_SHA: " + _new_SHA);

   var checksum = _new_SHA.slice(-8, _new_SHA.length);
   console.log("checksum:" + checksum);

   var almost_address = "00" + RIPEMD.toString() + checksum;
   console.log("almost_address:" + almost_address);

   var buffer = Buffer.from(almost_address, "hex");

   return BS58.encode(buffer);

}

For some reason it is not giving me the proper results. I'm wondering, what are the exact steps of deriving an address from a public key?
For those of your who are wondering here is what my code is doing:
  checksum = SHA256(SHA256(RIPEMD160(SHA256(public_key)))) <-- get last 8 bytes

  almost_address = 0x00 (network byte) and RIPEMD160(SHA256(public_key)) and checksum <-- compacted into 1 string

  address = base58(almost(address)

**Tags:** address, public-key

> **Comments:**
> **username_1**: this any help? https://bitcoin.stackexchange.com/questions/76181/bitcoin-public-keys-from-uncompressed-to-compressed-version-with-code-sample  

---

## 1 answers

### Answer by username_2 on 2019-05-15. Score: 3 | Accepted answer

You're hashing the string representation of things, not the actual hash itself. Hash the bytes of the hash, not the bytes of its string representation.

All of the should operations are on the bytes themselves, not the hexadecimal representation of those bytes which is what you have done.

> **Comments:**
> **username_3**: Also checksum is calculated _after_ prefixing version byte to rmd160(sha256(pubkey)) not before.  
> **username_0**: @username_3 the calculation is the same if you haven't noticed.  
> **username_3**: @Danshpaner: I have noticed it is _not_ the same. But go ahead and do whatever you want, it doesn't hurt me a bit.  

---

