All Products
Search
Document Center

Blockchain as a Service:Subscribe to Events

Last Updated:Mar 31, 2026

Streams real-time blockchain events from a blockchain network over a persistent WebSocket connection.

Request syntax

GET /api/v1/networks/{network}/events/subscribe

Request parameters

ParameterDescription
networkThe name of the channel.
access_tokenThe access token used to authenticate REST API requests.
sourceThe event types to subscribe to. Valid values: Tx, Config, Contract, Block. To subscribe to multiple types, separate them with commas (,). Use * to subscribe to all event types.

Message structure

Each message pushed over the WebSocket connection contains the following fields.

ParameterTypeDescription
idStringThe event ID, unique within the channel.
nameStringThe event name.
typeEventTypeThe event type. Valid values: Tx (transaction creation), Config (blockchain system configuration change), Contract (smart contract event set in a transaction), Block (block creation).
networkStringThe name of the channel.
instance_idStringThe instance ID of the subscribed event, unique within an organization.
contentObjectThe event payload. The structure depends on the event type: when type is Tx or Config, the value follows the Transaction structure; when type is Contract, the value is a Base64-encoded string; when type is Block, the value follows the Block structure.

Transaction structure

Applies when type is Tx or Config.

ParameterTypeDescription
idStringThe transaction ID. Empty when type is Config.
stateStringThe transaction state. VALID indicates a valid transaction. Any other value indicates an invalid transaction.
fromStringThe transaction initiator, in the format <Organization MSP>.<Username>, where MSP is the Membership Service Provider (MSP) identifier.
toStringThe target chaincode called by the transaction. Empty when type is Config.
inputStringThe JSON-encoded chaincode input parameters. When type is Config, this field contains the JSON-encoded common.ConfigUpdate value.
eventsList\<Event\>The blockchain events generated by the transaction.
dataObjectThe full transaction payload. The data structure is common.Payload.

Block structure

Applies when type is Block.

ParameterTypeDescription
numberIntegerThe block height.
hashStringThe hash of the current block, hex-encoded.
previous_hashStringThe hash of the previous block, hex-encoded.
create_timeIntegerThe block creation time as a UNIX timestamp, representing the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
transactionsList\<String\>The list of transaction IDs included in the block.

Examples

Connect to the event stream

wscat -c "ws://your.gateway.endpoint/api/v1/networks/channel3/events/subscribe?access_token=<Your URL Encoded Access Token>&source=%2A"

Sample block event message

{
  "type": "Block",
  "platform": "Fabric",
  "instance_id": "csi-e2ehmfqasth-bcw7tzao2dzeo",
  "network": "channel3",
  "id": "block-282",
  "name": "282",
  "content": {
    "number": 282,
    "hash": "f7b42d07509c463f8e8cde0fcc8325b42e8bf7fd6a7a24dd207eed297fcd6358",
    "create_time": 1581589504,
    "previous_hash": "b8de08d49217c1d8f4ea398c8c61fe2a5bc46ec7bb6c95f44dfd29eaf6c272ab",
    "transactions": [
      "dc90b701e27afa5120ee003ef9d51b86a2ff9e1a9d8537f65387bde6d92c5cba"
    ]
  }
}

Error codes

For more information, see Error codes.