Blockchain.com WebSocket API
Receive real-time Bitcoin transaction notifications, new block events, and address activity over the Blockchain.com public WebSocket gateway.
Receive real-time Bitcoin transaction notifications, new block events, and address activity over the Blockchain.com public WebSocket gateway.
The Blockchain.com WebSocket endpoint is a public JSON command channel — use the generic TsgcWebSocketClient to send op messages and receive utx/block events.
TsgcWebSocketClient
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Open a TsgcWebSocketClient against wss://ws.blockchain.info/inv, send the JSON subscribe commands and parse the incoming utx and block events.
uses
sgcWebSocket, sgcJSON;
var
WSClient: TsgcWebSocketClient;
begin
WSClient := TsgcWebSocketClient.Create(nil);
WSClient.URL := 'wss://ws.blockchain.info/inv';
WSClient.OnMessage := procedure(Connection: TsgcWSConnection; const Text: string)
begin
Memo1.Lines.Add(Text);
end;
WSClient.OnConnect := procedure(Connection: TsgcWSConnection)
begin
// Subscribe to all new bitcoin transactions
Connection.WriteData('{"op":"unconfirmed_sub"}');
// Receive new blocks
Connection.WriteData('{"op":"blocks_sub"}');
// Subscribe to a specific address
Connection.WriteData('{"op":"addr_sub","addr":"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"}');
end;
WSClient.Active := True;
end;
// uses: sgcWebSocket
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
WSClient->URL = "wss://ws.blockchain.info/inv";
// Hook OnMessage and OnConnect, then subscribe:
// WSClient->WriteData("{\"op\":\"unconfirmed_sub\"}");
// WSClient->WriteData("{\"op\":\"blocks_sub\"}");
WSClient->Active = true;
Blockchain.com exposes a simple JSON op-channel over WebSocket — use TsgcWebSocketClient directly.
Send {"op":"unconfirmed_sub"} after connect to receive every new mempool transaction as a {"op":"utx", "x":{...}} envelope.
{"op":"blocks_sub"} subscribes to new-block notifications — one {"op":"block", "x":{...}} arrives per mined block (note the protocol may publish more than one event when a chain split occurs).
{"op":"addr_sub","addr":"<bitcoin-address>"} subscribes to inbound/outbound transactions for a single address. Use "addr_unsub" to stop.
Because Blockchain.com uses a plain JSON command channel, the TsgcWebSocketClient component is enough — no exchange-specific Delphi class is required.
Configure WatchDog on the client to auto-reconnect on network drops, and HeartBeat with a TCP-level ping to keep the connection alive through NAT timeouts.
Receive each frame in OnMessage, then parse with sgcJSON or your preferred JSON library. The transaction body sits under the x field of the envelope.
Authoritative sources for the APIs this component connects to.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — API_Blockchain Notes on connecting to the Blockchain.com WebSocket gateway from Delphi. | Open | |
| Free Trial — sgcWebSockets Download the trial package to use TsgcWebSocketClient against any public WebSocket endpoint. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |