<p>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.'</p>

<p>We can take the transaction you listed as an example and decode it:</p>

<p>Starting with the transaction hash:
2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba</p>

<p>We get the hex string using <a href="https://blockchain.info/api/blockchain_api" rel="nofollow noreferrer">blockchain.info's api</a>:</p>

<p><a href="https://blockchain.info/rawtx/2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba?format=hex" rel="nofollow noreferrer">https://blockchain.info/rawtx/2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba?format=hex</a></p>

<p>Which gives us the hex:</p>

<p>0100000001923f8a599a04a21ef10da6330a21d29fe162d653267da012d6eededb55702e4e010000008a47304402203207e257255a21ac32fe2203f3356f6a5303b8cfca6a6b66c16a23d68f818ff902206a83cce8450aac66f300f0579d4274c6d9852ef3ea74826c9817b87dd9a0abec0141049778e7a85cad5d71cec7fde276842f744f0615897a3f28015489bf2b4bbfda11227e84ff553d7d0762baf5ff50371dfec0c1bf6f5a8ff9937e6bc9c431297981ffffffff02008c86470000000017a914ed3001d36afe91700b20d07bef089323daacc6788750647800000000001976a9140cb6c275be7f179883bb821ef1dfd6b520fc656988ac00000000</p>

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

<p><a href="http://chainquery.com/bitcoin-api/decoderawtransaction" rel="nofollow noreferrer">http://chainquery.com/bitcoin-api/decoderawtransaction</a></p>

<p>Pasting the hex from above will give you information about the transaction. </p>

CC BY-SA 4.0
2018-05-19T14:09:55.257Z
Happy to see that my answer helped :) If you could mark it as 'answered' that would be great!
timothyylim
CC BY-SA 4.0
2018-05-21T13:45:09.683Z
Um - how do you mark it as 'answered'?
rodmclaughlin
CC BY-SA 4.0
2018-05-21T16:19:50.473Z
There should be a tick/check that you can press on the left hand side of my answer :)
timothyylim
CC BY-SA 4.0
2018-05-18T10:47:01.910Z
2018-05-18T10:47:01.910Z
timothyylim
<p>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.</p>

<p>blockchain.ex:</p>

<pre><code>      def getrawtransaction( trans ), do: bitcoin_rpc( "getrawtransaction", [trans] )

      def decoderawtransaction( hex ), do: bitcoin_rpc( "decoderawtransaction", [hex] )
</code></pre>

<p>transaction_view.ex:</p>

<p>transaction is a string like this:  "79895513e10d92fee5be47ec11c02bb29078ee0f7f3ca29e16afe113ff94c3d3"</p>

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

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

      defp get_transaction( transaction ) do
        hex = get_hex transaction
        Blockchain.decoderawtransaction( hex )
      end
</code></pre>

CC BY-SA 4.0
2018-05-23T03:53:03.840Z
2018-05-23T03:53:03.840Z
rodmclaughlin
<p>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</p>

<p><a href="https://blockchain.info/block/00000000000000000028d1186d6dc9191a6ec93624141031e31814e22e75e0c5" rel="nofollow noreferrer">https://blockchain.info/block/00000000000000000028d1186d6dc9191a6ec93624141031e31814e22e75e0c5</a></p>

<p>has transactions including 2c1a83d5a511399f151571ff26925764ef73081251c239dd2eb6904304d7bcba</p>

<p>from which blockchain.info has deduced </p>

<p>1PSfpNCcY9uNh1QEitLLLGaDX5LicnBJhx sent 12 BTC to</p>

<p>3PK9abqzd2oK3yWgESSZ6Ps1wPBBu222VW and 0.0789 BTC to</p>

<p>12AE3fQj1CsSGL9c3aZpkSDz991KUxntvB </p>

<p>I want to find out how it deduced it. Thanks for any information.</p>

CC BY-SA 4.0
2018-05-19T14:09:25.060Z
Happy to see that my answer helped :) If you could mark it as 'answered' that would be great!
timothyylim
<transactions>
How do you extract the sending and receiving addresses, and the amount, from a Bitcoin transaction?
rodmclaughlin
# How do you extract the sending and receiving addresses, and the amount, from a Bitcoin transaction?

(Asked by: username_0 on 2018-05-18)

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.

**Tags:** transactions

> **Comments:**
> **username_1**: Happy to see that my answer helped :) If you could mark it as 'answered' that would be great!  

---

## 2 answers

### Answer by username_1 on 2018-05-18. Score: 0 | Accepted answer

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/api/blockchain_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.

> **Comments:**
> **username_1**: Happy to see that my answer helped :) If you could mark it as 'answered' that would be great!  
> **username_0**: Um - how do you mark it as 'answered'?  
> **username_1**: There should be a tick/check that you can press on the left hand side of my answer :)  

---

### Answer by username_0 on 2018-05-23. Score: 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


---

