1

OK, I am sure that this is a really dumb, rookie question, so sorry in advance... I am trying to read through the blockchain and display the receiving address(es) for all transactions in the chain. (Just like Blockchain-Explorer would do.) My library is NBitCoin in C#, so I am not really working through the raw data here. My starting point is the the Hash that is in the output transaction part (TxOut.ScriptPubKey.PaymentScript.Hash). I read in another post that in order to convert that Base160 encoded hash to a BitCoin address I would have to add 00 in front and then do a Base58 encode of the resulting array. So I did that:

Base58Encoding.Encode(ArrayHelpers.ConcatArrays(DoubleZero,TO.ScriptPubKey.PaymentScript.Hash.ToBytes()))

Then I took a sample and compared it with the output blockexplorer.com had for the same transaction, and unfortunately it didn't match. (And yes, I checked the comment made in this question (Deriving the Bitcoin address from the raw block script), my test transaction has a Base160 encoding, so according to my understanding it was sent to an address. The hash is: caf74d35ff967c946f99588cb03b774350d83331 My generated output is: 13q1EyUVtUfvpixnYkDRoZUsi5ZVi Blockexplorer.com shows: 16va6NxJrMGe5d2LP6wUzuVnzBBoKQZKom

Just for the sake of it I tried using all the other hashes in that ScriptPubKey block as well, but none yielded the result blockexplorer.com had. What am I missing here? thx

  • I am not familiar with c#, but this looks to me as if you are not working on the hex representation of data. I usually check here: gobittest.appspot.com/Address, and when I enter in step9 your result, it shows the hash. Cleaning and re-entering the hash in step 3 results into a different address. I had a similiar problem with the shell scripts, look at the reply from Dave here: bitcoin.stackexchange.com/questions/46455/… – pebwindkraft Oct 15 '17 at 9:09
0

my test transaction has a Base160 encoding, so according to my understanding it was sent to an address

I guess you mean ripemd160 or base 16 (hexadecimal) rather than Base160. Ripemd160 is just a hashing algorithm so the output is just bytes, probably encoded in hex (base 16). You can guess it is a ripemd hash based on its length, but not based on its encoding, because the entire transaction is usually displayed in hex.

But to convert from a pubkey hash to an address, you also have to add the checksum onto the end, rather than just the version byte (the 0x00). That is most likely why you are getting a different result, because you have no created a checksum before encoding it with base58.

See the steps outlined here for more info: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#How_to_create_Bitcoin_Address

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.