<blockquote>
  <p><strong>I am unable to see the amount credited to this new address with the getreceivedbyaddress command.</strong></p>
</blockquote>

<p>There is no by-address index of the blockchain in Bitcoin core.</p>

<p>For bitcoin-core to track an address you must, for example, add an address to the wallet as a watch-only address.</p>

CC BY-SA 4.0
2018-11-14T11:10:48.043Z
2018-11-14T11:10:48.043Z
RedGrittyBrick
<p>If I have the bitcoin address, the private key and a transaction ID from Bitcoin (<code>regtest</code> mode) in shell variables, what Python code do I need to run to claim the Bitcoins are indeed intended for this private key?</p>

<p>I have been following this excellent article - <a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">Bitcoins the hard way : Using the raw Bitcoin protocol</a>. I hope to replicate this with Bitcoin in <a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">regtest mode</a> as part of a larger design.</p>

<p>To begin with, I had to ensure that the code mentioned in the article (available <a href="https://github.com/shirriff/bitcoin-code" rel="nofollow noreferrer">here</a>) can generate Bitcoin address with <code>m</code> or <code>n</code> as the prefix and uses <code>111</code> as the network ID. See <a href="https://en.bitcoin.it/wiki/List_of_address_prefixes" rel="nofollow noreferrer">here</a>. I made the following code changes to generate addresses for <code>regtest</code> mode:</p>

<h2>keyUtils.pubKeyToAddr</h2>

<p><code>
def pubKeyToAddr(s):
    ripemd160 = hashlib.new('ripemd160')
    ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
    return utils.base58CheckEncode(111, ripemd160.digest())
</code></p>

<h2>utils.base58CheckEncode</h2>

<p><code>
def base58CheckEncode(version, payload):
    s = chr(version) + payload
    checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4]
    result = s + checksum
    leadingZeros = countLeadingChars(result, '\0')
    return 'm' * leadingZeros + base58encode(base256decode(result))
</code></p>

<p>Then, with <code>bitcoin-qt</code>, I transferred some BTC to an address generated from above. The transfer goes through and is confirmed when a new block is created. </p>

<p>However, I am unable to see the amount credited to this new address with the <code>getreceivedbyaddress</code> command. I am running this command in the Debug Window console (for some reason, <code>bitcoin-cli</code> wouldn't connect even after <a href="https://bitcoin.org/en/developer-examples" rel="nofollow noreferrer">configuring</a> <code>bitcoind</code>). I think, the reason could be the fact that, the private key and the bitcoin address was generated elsewhere from command line rather than the default <code>--data-dir</code> location that <code>bitcoin-qt</code> used when it was launched. I understand this.</p>

CC BY-SA 3.0
2017-02-05T20:54:35.073Z
Did you import either the private key or the address into Bitcoin Core's wallet? getreceivedbyaddress is a wallet RPC and can only know about transactions that the wallet considers to be its own.
Pieter Wuille
CC BY-SA 3.0
2017-02-06T00:35:09.627Z
Actually I don't want to import the private keys into the wallet that belongs to the full node. I want to treat the mabuakky created Bitcoin address as a separate wallet .
cogitoergosum
CC BY-SA 3.0
2017-02-06T00:45:44.297Z
Bitcoin Core only supports one wallet for now.
Pieter Wuille
CC BY-SA 3.0
2017-02-06T00:54:07.067Z
You don't need to import the private key, by the way. You can just import the address (with `importaddress`) as a watch-only address.
Pieter Wuille
CC BY-SA 3.0
2017-02-06T01:06:00.840Z
Did you mean, only one wallet is supported in the `regtest` mode?
cogitoergosum
CC BY-SA 3.0
2017-02-06T01:08:06.227Z
If the store of transactions is a BerkleyDB, surely, it should be as easy as running a query against that DB with my Bitcoin address as the input? The query output could be just the hex string that can be solved only by me because I own the private key.
cogitoergosum
CC BY-SA 3.0
2017-02-06T01:13:36.613Z
Bitcoin Core has no database per address, and it doesn't need it. Its wallet only keeps track of the relevant transactions. If you want to use getreceivedbyaddress, you must make the wallet track that address first.
Pieter Wuille
CC BY-SA 3.0
2017-02-06T01:18:37.150Z
Sorry, I didn't mean a per address database. I was referring to the blockchain itself. Quoting your answer here ( :D ) - http://bitcoin.stackexchange.com/a/11108/6975 - I was thinking, if I can query `blocks/blk*.dat` with my Bitcoin address as the input. After all, https://blockchain.info/ allows searching via address. So, why not in this case too?
cogitoergosum
CC BY-SA 3.0
2017-02-06T02:16:26.010Z
There is no by-address index of the blockchain, as there is no need for one. Scanning through the chain is possible (and the wallet will do that for you at import time), but that may easily take dozens of minutes by- not something you want to do when you issue an RPC call.
Pieter Wuille
CC BY-SA 3.0
2017-02-06T02:20:00.363Z
blockchain.info has a massive database pre-indexed for every address. That's not implemented in Bitcoin Core, and you generally don't need it. Letting the wallet track transactions that are relevant is far more scalable.
Pieter Wuille
CC BY-SA 3.0
2017-02-06T02:48:36.640Z
Thank you, @PieterWuille, for the explanation. I think, I will just create another node and move on.
cogitoergosum
<transactions><wallet><address>
Manually checking for credited bitcoins
cogitoergosum
# Manually checking for credited bitcoins

(Asked by: username_0 on 2017-02-05)

If I have the bitcoin address, the private key and a transaction ID from Bitcoin (`regtest` mode) in shell variables, what Python code do I need to run to claim the Bitcoins are indeed intended for this private key?

I have been following this excellent article - [Bitcoins the hard way : Using the raw Bitcoin protocol](http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html). I hope to replicate this with Bitcoin in [regtest mode](http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html) as part of a larger design.

To begin with, I had to ensure that the code mentioned in the article (available [here](https://github.com/shirriff/bitcoin-code)) can generate Bitcoin address with `m` or `n` as the prefix and uses `111` as the network ID. See [here](https://en.bitcoin.it/wiki/List_of_address_prefixes). I made the following code changes to generate addresses for `regtest` mode:

## keyUtils.pubKeyToAddr

`def pubKeyToAddr(s):
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
return utils.base58CheckEncode(111, ripemd160.digest())`

## utils.base58CheckEncode

`def base58CheckEncode(version, payload):
s = chr(version) + payload
checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4]
result = s + checksum
leadingZeros = countLeadingChars(result, '\0')
return 'm' * leadingZeros + base58encode(base256decode(result))`

Then, with `bitcoin-qt`, I transferred some BTC to an address generated from above. The transfer goes through and is confirmed when a new block is created.

However, I am unable to see the amount credited to this new address with the `getreceivedbyaddress` command. I am running this command in the Debug Window console (for some reason, `bitcoin-cli` wouldn't connect even after [configuring](https://bitcoin.org/en/developer-examples) `bitcoind`). I think, the reason could be the fact that, the private key and the bitcoin address was generated elsewhere from command line rather than the default `--data-dir` location that `bitcoin-qt` used when it was launched. I understand this.

**Tags:** transactions, wallet, address

> **Comments:**
> **username_1**: Did you import either the private key or the address into Bitcoin Core's wallet? getreceivedbyaddress is a wallet RPC and can only know about transactions that the wallet considers to be its own.  
> **username_0**: Actually I don't want to import the private keys into the wallet that belongs to the full node. I want to treat the mabuakky created Bitcoin address as a separate wallet .  
> **username_1**: Bitcoin Core only supports one wallet for now.  
> **username_1**: You don't need to import the private key, by the way. You can just import the address (with `importaddress`) as a watch-only address.  
> **username_0**: Did you mean, only one wallet is supported in the `regtest` mode?  
> **username_0**: If the store of transactions is a BerkleyDB, surely, it should be as easy as running a query against that DB with my Bitcoin address as the input? The query output could be just the hex string that can be solved only by me because I own the private key.  
> **username_1**: Bitcoin Core has no database per address, and it doesn't need it. Its wallet only keeps track of the relevant transactions. If you want to use getreceivedbyaddress, you must make the wallet track that address first.  
> **username_0**: Sorry, I didn't mean a per address database. I was referring to the blockchain itself. Quoting your answer here ( :D ) - http://bitcoin.stackexchange.com/a/11108/6975 - I was thinking, if I can query `blocks/blk*.dat` with my Bitcoin address as the input. After all, https://blockchain.info/ allows searching via address. So, why not in this case too?  
> **username_1**: There is no by-address index of the blockchain, as there is no need for one. Scanning through the chain is possible (and the wallet will do that for you at import time), but that may easily take dozens of minutes by- not something you want to do when you issue an RPC call.  
> **username_1**: blockchain.info has a massive database pre-indexed for every address. That's not implemented in Bitcoin Core, and you generally don't need it. Letting the wallet track transactions that are relevant is far more scalable.  
> **username_0**: Thank you, @username_1, for the explanation. I think, I will just create another node and move on.  

---

## 1 answers

### Answer by username_2 on 2018-11-14. Score: 1

> **I am unable to see the amount credited to this new address with the getreceivedbyaddress command.**

There is no by-address index of the blockchain in Bitcoin core.

For bitcoin-core to track an address you must, for example, add an address to the wallet as a watch-only address.


---

