<p>figured it out after finding my own previous post about how I found out this info with americancoind, <a href="https://bitcoin.stackexchange.com/questions/19971/coin-seems-to-have-gone-to-a-duplicate-address">coin seems to have gone to a duplicate address</a>, by its error message on attempting to resend the raw transaction. but bitcoind doesn't tell you what block it's in, merely stating <code>error: {"code":-5,"message":"transaction already in block chain"}</code>. however, on searching through the source (rpcrawtransaction.cpp) I noticed that getrawtransaction takes an extra arg, verbose, which if greater than 0 gives the blockhash:</p>

<pre><code>jcomeau@aspire:~/rentacoder/jcomeau/bitcoin/src$ bitcoind getrawtransaction 3dd264f603f75871c5a36b61db8e137d8cee6b019a8d5bdfdabd7383ccc47068 1 | grep block
    "blockhash" : "000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a",
    "blocktime" : 1393013064
</code></pre>

<p>and with the blockhash you can use getblock:</p>

<pre><code>jcomeau@aspire:~/rentacoder/jcomeau/bitcoin/src$ bitcoind getblock 000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a
{
    "hash" : "000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a",
    "confirmations" : 255,
    "size" : 341358,
    "height" : 287092,
    "version" : 2,
    "merkleroot" : "d0fd6154ba64682b48c9c15600ee7c8594336cf4c0a2917b5cbcf1f5a74d2096",
</code></pre>

<p>so, 287092 is the block number that contains the transaction.</p>

CC BY-SA 3.0
2014-02-23T07:07:08.380Z
2014-02-23T17:06:56.733Z
2017-04-13T12:47:33.283Z
jcomeau_ictx
<p>I realize this can be done at blockchain.info, but would like to find a way to do this with just the bitcoind client. if all I have is the receiving address and the transaction number, I can't figure out what command or set of commands to use. I can get and decode the raw transaction (<code>bitcoind decoderawtransaction $(bitcoind getrawtransaction 3dd264f603f75871c5a36b61db8e137d8cee6b019a8d5bdfdabd7383ccc47068) | less</code>), but that doesn't give me the block number. </p>

<p>note that I can't use <code>gettransaction</code> because my local box (netbook) isn't the origin nor the destination of the transaction; I get <code>error: {"code":-5,"message":"Invalid or non-wallet transaction id"}</code>. I also can't use <code>listreceivedbyaddress</code> for the same reason, although I don't get an error in this case because I did once send to the address in question from my netbook.</p>

CC BY-SA 3.0
2014-02-21T23:16:19.210Z
note to people coming across this question: don't mark down Luca's answer, I hadn't made it clear at the beginning that I couldn't use  gettransaction. added that  in just now.
jcomeau_ictx
CC BY-SA 3.0
2014-02-23T05:20:02.057Z
This may be impossible to do without looking up each block down until you get to one that contains it.
John T
CC BY-SA 3.0
2014-02-23T05:26:15.923Z
yeah, I'm beginning to think that's probably my only option. I guess that's what blockchain.info does too, just loads all the blocks into a database.
jcomeau_ictx
CC BY-SA 3.0
2014-02-23T05:30:45.470Z
If you're good with Javascript this can be done easily with [Bitcore](http://bitcore.io/). It's really interesting and powerful.
John T
<bitcoind>
how does one map a transaction number to a block with just the bitcoind client?
jcomeau_ictx
# how does one map a transaction number to a block with just the bitcoind client?

(Asked by: username_0 on 2014-02-21)

I realize this can be done at blockchain.info, but would like to find a way to do this with just the bitcoind client. if all I have is the receiving address and the transaction number, I can't figure out what command or set of commands to use. I can get and decode the raw transaction (`bitcoind decoderawtransaction $(bitcoind getrawtransaction 3dd264f603f75871c5a36b61db8e137d8cee6b019a8d5bdfdabd7383ccc47068) | less`), but that doesn't give me the block number.

note that I can't use `gettransaction` because my local box (netbook) isn't the origin nor the destination of the transaction; I get `error: {"code":-5,"message":"Invalid or non-wallet transaction id"}`. I also can't use `listreceivedbyaddress` for the same reason, although I don't get an error in this case because I did once send to the address in question from my netbook.

**Tags:** bitcoind

> **Comments:**
> **username_0**: note to people coming across this question: don't mark down Luca's answer, I hadn't made it clear at the beginning that I couldn't use  gettransaction. added that  in just now.  
> **username_1**: This may be impossible to do without looking up each block down until you get to one that contains it.  
> **username_0**: yeah, I'm beginning to think that's probably my only option. I guess that's what blockchain.info does too, just loads all the blocks into a database.  
> **username_1**: If you're good with Javascript this can be done easily with [Bitcore](http://bitcore.io/). It's really interesting and powerful.  

---

## 1 answers

### Answer by username_0 on 2014-02-23. Score: 0 | Accepted answer

figured it out after finding my own previous post about how I found out this info with americancoind, coin seems to have gone to a duplicate address, by its error message on attempting to resend the raw transaction. but bitcoind doesn't tell you what block it's in, merely stating error: {"code":-5,"message":"transaction already in block chain"}. however, on searching through the source (rpcrawtransaction.cpp) I noticed that getrawtransaction takes an extra arg, verbose, which if greater than 0 gives the blockhash:
jcomeau@aspire:~/rentacoder/jcomeau/bitcoin/src$ bitcoind getrawtransaction 3dd264f603f75871c5a36b61db8e137d8cee6b019a8d5bdfdabd7383ccc47068 1 | grep block
    "blockhash" : "000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a",
    "blocktime" : 1393013064

and with the blockhash you can use getblock:
jcomeau@aspire:~/rentacoder/jcomeau/bitcoin/src$ bitcoind getblock 000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a
{
    "hash" : "000000000000000116f3abab7d0f620f620eae189de29ddb06fe8baae566467a",
    "confirmations" : 255,
    "size" : 341358,
    "height" : 287092,
    "version" : 2,
    "merkleroot" : "d0fd6154ba64682b48c9c15600ee7c8594336cf4c0a2917b5cbcf1f5a74d2096",

so, 287092 is the block number that contains the transaction.


---

