2

I have this code:

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
rpc_user='-------' #User name is hidden
rpc_password='-------' #Password hidden
logging.basicConfig()
logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)
rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))
blockcount=rpc_connection.getblockcount()
print(blockcount)

The result:

DEBUG:BitcoinRPC:-1-> getblockcount []
DEBUG:BitcoinRPC:<-1- 94768
94768

Of course this is last block in my device, but I want the real last block.

Is there a "external server or a Web site" i can call instead of Local server '127.0.0.1'? (for sending the bitcoin RBC method)

3

Instead of getblockcount, you can call getblockchaininfo and read the headers field.

However, while this may give you a lot more blocks than the local block count, you will still only receive a count up to the point where your node has synced headers (which can be limited by time, network, how well synced your peers are)

There is no way to always get the latest block height reliably from an unsynced node.

  • One could additionally check the timestamp in order to at least know whether this is a recent block. – Murch Jul 1 '18 at 22:07
0

You would have to try to connect live nodes to get that information.

https://bitnodes.earn.com/nodes/?q=United%20States

Lists active nodes of BTC network.

You should find some node which allows RPC connection on the port.

0

Of course this is last block in my device, but I want the real last block.

There is no such thing. If there was a "real last block" that was clearly and unambiguously determinable, we would not need a blockchain.

The best you can do is run a node, and ask the node what's the best block it knows about. Or you can trust someone to run such a node and ask them.

Perhaps another way of seeing it: there is no distinction between a synced or unsynced node. Your node is always trying to synchronize with whatever other nodes in the network tell it. It can't know what the actual latest/best block on the network is, as at the very least the speed of light around the globe is limited.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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