Bitcoin Forum
May 21, 2024, 03:16:43 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: get all transactions from a block [bitcoind]  (Read 872 times)
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
September 04, 2014, 01:03:35 AM
 #1

Hey there,

I'm playing around with rpc calls to a bitcoind instance.  I can get the info about a given block by passing its hash to 'getblock':

Code:
$ h=`bitcoind getblockhash 150000`
$ bitcoind getblock $h
{
    "hash" : "0000000000005e5fd51f764d230441092f1b69d1a1eeab334c5bb32412e8dc51",
    "confirmations" : 128754,
    "size" : 410,
    "height" : 150000,
    "version" : 2,
    "merkleroot" : "ea6054d3d19ea2cc460809179b93946cfb4dac4db48837eb5e3ba3d150ae3ddd",
    "tx" : [
        "235b91c7b53c100f9f836ad17b6e0e417279efda77606d490ec743817bac6ff6",
        "1b1202259a5c28f8e81dbc6d1ddd5bbf37d3af18d549495b2b9ad315fb9738a8"
    ],
    "time" : 1386098130,
    "nonce" : 2666252006,
    "bits" : "1b24a835",
    "difficulty" : 1787.78664453,
    "chainwork" : "000000000000000000000000000000000000000000000000028360d5673d92a9",
    "previousblockhash" : "00000000002380e843bcef7c5656498fd55caa64243cd60acb329ec8bb0f6699",
    "nextblockhash" : "000000000023a097d684c7c3be7a9410b85337374b8d7786cdbe38e947608e1b"
}

Do I need to parse one of these fields in order to get a list of transactions included in this block?  If so, where do I find the spec for that operation?  Or is there another rpc call that I should be making?
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
September 04, 2014, 01:20:13 AM
 #2

Do I need to parse one of these fields in order to get a list of transactions included in this block?

Yes.

If so, where do I find the spec for that operation?

Code:
$ h=`bitcoind getblockhash 150000`
$ bitcoind getblock $h
{
 - snip -
    "tx" : [
        "235b91c7b53c100f9f836ad17b6e0e417279efda77606d490ec743817bac6ff6",
        "1b1202259a5c28f8e81dbc6d1ddd5bbf37d3af18d549495b2b9ad315fb9738a8"
    ],
- snip -
}

There you go.  There's your list of transactions.

Or is there another rpc call that I should be making?

If you want the actual details of each transaction, you'll need to call getrawtransaction and decoderawtransaction for each transaction in the list.
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
September 04, 2014, 01:33:21 AM
 #3

Thanks!  I just realized this myself after posting.  I think I didn't notice it because there were only 2 transactions in that random block I illustrated with.

I'm now playing with getrawtransaction.  Cheers!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!