Our websocket API allows developers to receive realtime notifications about new transactions and blocks. The Websocket echo test can be useful for debugging.

Connection URL:

ws://ws.blockchain.info/inv

OR

ws://ws.blockchain.info:8335/inv

Status Updates

Regardless of channel subscription you may receive status messages. This should be displayed to the user.

{"op":"status", "msg", "Connected, Subscribed, Welcome etc..."}

Once the socket is open you can subscribe to a channel by sending an "op" message.

Subscribing to Unconfirmed transactions

Subscribe to notifications for all new bitcoin transactions.

{"op":"unconfirmed_sub"}

Subscribing to an Address

Receive new transactions for a specific bitcoin address:

{"op":"addr_sub", "addr":"$bitcoin_address"}

Message on new transaction:

	
{
    "op": "utx",
    "x": {
        "hash": "f6c51463ea867ce58588fec2a77e9056046657b984fd28b1482912cdadd16374",
        "ver": 1,
        "vin_sz": 4,
        "vout_sz": 2,
        "lock_time": "Unavailable",
        "size": 796,
        "relayed_by": "209.15.238.250",
        "tx_index": 3187820,
        "time": 1331300839,
        "inputs": [
            {
                "prev_out": {
                    "value": 10000000,
                    "type": 0,
                    "addr": "12JSirdrJnQ8QWUaGZGiBPBYD19LxSPXho"
                }
            }
        ],
        "out": [
            {
                "value": 2800000000,
                "type": 0,
                "addr": "1FzzMfNt46cBeS41r6WHDH1iqxSyzmxChw"
            }
        ]
    }
}

Subscribing to new Blocks

Receive notifications when a new block is found. Note: if the chain splits you will receive more than one notification for a speicifc block height.

{"op":"blocks_sub"}

Message On New Block:

{
    "op": "block",
    "x": {
        "txIndexes": [
            3187871,
            3187868
        ],
        "nTx": 0,
        "totalBTCSent": 0,
        "estimatedBTCSent": 0,
        "reward": 0,
        "size": 0,
        "blockIndex": 190460,
        "prevBlockIndex": 190457,
        "height": 170359,
        "hash": "00000000000006436073c07dfa188a8fa54fefadf571fd774863cda1b884b90f",
        "mrklRoot": "94e51495e0e8a0c3b78dac1220b2f35ceda8799b0a20cfa68601ed28126cfcc2",
        "version": 1,
        "time": 1331301261,
        "bits": 436942092,
        "nonce": 758889471
    }
}
		

Debugging OPs:

{"op":"ping_block"}

Responds with the latest block

{"op":"ping_tx"}

Responds with the latest transaction. If subscribed to any addresses it will respond with the latest transaction involving those addresses.