How do I query a remote bitcoin node like RPC?

3

1

I know how to query the blockchain stored on my machine programmatically using bitcoind commands. Is it possible to do the same on a public node?

For example, is it possible to send “getblockcount” over the internet to bitcoinstats.com, hard-coded in the bitcoin source, or to inductivesoul.us, found in the bitcoin.it wiki? What are the steps to do so?

Edit

The quick answer is:

  • No, you cannot use bitcoind commands.
  • You have to communicate with a remote node using TCP.
  • You have to use a different set of commands found in the Protocol Specification.

u2843

Posted 2014-10-12T11:58:28.637

Reputation: 95

Answers

4

Excellent question, and welcome to the community!

Short Answer

Maybe.

Long answer

Yes, you can send queries to other nodes on the Bitcoin network. Note that these aren't RPC calls, but Bitcoin's underlying communication protocol. That means that all of the calls will be a little different, and some of them won't exist.

Examples:

  • There's no equivalent to getblockcount in the underlying protocol. Instead, you can connect to a node and listen for its version message, and look at the start_height field.

  • Instead of getrawmempool, you use mempool.

  • Instead of getpeerinfo, you use getaddr.

  • There's no equivalent to stop, because that would be stupid.

Also, if you're trying to query other nodes on the network, one of these libraries will be very helpful:

(If you're not using one of these languages, leave a comment.)

Nick ODell

Posted 2014-10-12T11:58:28.637

Reputation: 26 536

Is there an API library for PHP?rishta 2017-06-28T08:25:26.067

@rishta Don't think so. Didn't find any while googling.Nick ODell 2017-06-28T19:53:53.823