1

I'm trying to write software in Elixir to do it. I have the source code for BitcoinJ, but it's quite laborious figuring out what it does. If I look on bitcoin.info, I can see this block

https://blockchain.info/block/00000000000000000028d1186d6dc9191a6ec93624141031e31814e22e75e0c5

has transactions including 2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba

from which blockchain.info has deduced

1PSfpNCcY9uNh1QEitLLLGaDX5LicnBJhx sent 12 BTC to

3PK9abqzd2oK3yWgESSZ6Ps1wPBBu222VW and 0.0789 BTC to

12AE3fQj1CsSGL9c3aZpkSDz991KUxntvB

I want to find out how it deduced it. Thanks for any information.

1
  • Happy to see that my answer helped :) If you could mark it as 'answered' that would be great! Commented May 19, 2018 at 14:09

2 Answers 2

0

Bitcoin transactions are serialized into a hex string that contains all the necessary information to execute the transaction such as input and output values and origin and destination addresses. Blockchain.info decodes transaction hex strings to show this information.'

We can take the transaction you listed as an example and decode it:

Starting with the transaction hash: 2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba

We get the hex string using blockchain.info's api:

https://blockchain.info/rawtx/2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba?format=hex

Which gives us the hex:

0100000001923f8a599a04a21ef10da6330a21d29fe162d653267da012d6eededb55702e4e010000008a47304402203207e257255a21ac32fe2203f3356f6a5303b8cfca6a6b66c16a23d68f818ff902206a83cce8450aac66f300f0579d4274c6d9852ef3ea74826c9817b87dd9a0abec0141049778e7a85cad5d71cec7fde276842f744f0615897a3f28015489bf2b4bbfda11227e84ff553d7d0762baf5ff50371dfec0c1bf6f5a8ff9937e6bc9c431297981ffffffff02008c86470000000017a914ed3001d36afe91700b20d07bef089323daacc6788750647800000000001976a9140cb6c275be7f179883bb821ef1dfd6b520fc656988ac00000000

Almost all bitcoin libraries (in whatever language) have functions to decode hex strings. Here's an online service that lets you decode the hex:

http://chainquery.com/bitcoin-api/decoderawtransaction

Pasting the hex from above will give you information about the transaction.

3
  • Happy to see that my answer helped :) If you could mark it as 'answered' that would be great! Commented May 19, 2018 at 14:09
  • Um - how do you mark it as 'answered'? Commented May 21, 2018 at 13:45
  • There should be a tick/check that you can press on the left hand side of my answer :) Commented May 21, 2018 at 16:19
0

I'd like to just add to the answer above. I'm writing a Phoenix/Elixir app. I found that I can do all of the above using Blockchain RPC commands.

blockchain.ex:

      def getrawtransaction( trans ), do: bitcoin_rpc( "getrawtransaction", [trans] )

      def decoderawtransaction( hex ), do: bitcoin_rpc( "decoderawtransaction", [hex] )

transaction_view.ex:

transaction is a string like this: "79895513e10d92fee5be47ec11c02bb29078ee0f7f3ca29e16afe113ff94c3d3"

      def mark_up_transaction( transaction ) do
        result = get_transaction( transaction )
        case elem( result, 0 ) do
          :ok -> Poison.encode!( elem( result, 1 ), pretty: true )
          :error -> Poison.encode!( String.downcase( elem( result, 1 )[ "message" ] ), pretty: true )
          _ -> Poison.encode!( "unknown error", pretty: true )
        end
      end

      defp get_hex( transaction ) do
        result = Blockchain.getrawtransaction transaction
        case result do
          {:ok, hex } -> hex
          {:invalid, {:ok, hex }} -> hex # Why it does this I don't know, but it did
          {_, {:ok, hex }} -> hex
          _ -> nil
        end
      end

      defp get_transaction( transaction ) do
        hex = get_hex transaction
        Blockchain.decoderawtransaction( hex )
      end

Your Answer

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

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