Listen to transactions

Transactions are exposed via subscriptions over WebSocket. Applications can create subscriptions using our official SDKs or via standard eth_subscribe JSON-RPC methods. SDKs are faster, but websockets are more convenient.

Ethereum, Polygon and Binance Smart Chain are currently supported.

Get an API Key in the Merkle Developer Dashboard

newPendingTransactions

Our standard RPC interface seamlessly integrates with existing applications. The transaction stream is accessible through standard eth_subscribe commands, ensuring compatibility with a wide range of existing Web3 libraries and tools. By leveraging this functionality, developers can easily subscribe to real-time notifications of transaction events.

The RPC endpoint structure is the following

wss://txs.merkle.io/rpc/{api-key}/{chain-id}

The chain ID must follow the format described in the table and defaults to mainnet when omitted:

Pending transaction with just hashes

This is the RPC method to retrieve pending transaction hashes.

Request

wscat -c wss://txs.merkle.io/rpc/{api-key}/mainnet \
-x '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_subscribe",
  "params": [
    "newPendingTransactions"
  ]
}'

Response

{
    "jsonrpc": "2.0",
    "method": "eth_subscription",
    "params": {
        "subscription": "0xc3b33bb549fb9a60e95d21862596617c",
        "result": "0xd6fdc5cc41a9959e922f30cb772a9aef46f4daea279307bc5f7024edc4ccd7fa"
    }
}

Pending transactions with full body

This is the RPC method to retrieve full detailed pending transactions.

Request

wscat -c wss://txs.merkle.io/rpc/{api-key}/mainnet \
-x '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_subscribe",
  "params": [
    "newPendingTransactions",
    true
  ]
}'

Response

{
    "jsonrpc": "2.0",
    "method": "eth_subscription",
    "params": {
        "subscription": "0x3d8cef838df23e6227aa448a2fb82150",
        "result": {
            "hash": "0xf53e9b35ebd3538eefab139978162a6411efe7e887d20ff88a04faef0531ef4e",
            "nonce": "0x12b",
            "blockHash": null,
            "blockNumber": null,
            "transactionIndex": null,
            "from": "0x5f66468b7a18788156df9ad38ce9b71f72c8a84e",
            "to": "0x264e1a5fcb2cc769e93e043572f2391e181cc500",
            "value": "0x2aa1efb94e0000",
            "gasPrice": "0xc5c09e483",
            "gas": "0x5208",
            "maxFeePerGas": "0xc5c09e483",
            "maxPriorityFeePerGas": "0x5f5e100",
            "input": "0x",
            "r": "0x2e0b6765e31364f8d94f7ffe01a44028faac1f81ceab0aabbc0e1b6933ebab77",
            "s": "0x2d374b7fdda33e0ba3c74d47a7950ba217fd54da144fafda42c7efe1b0d78673",
            "v": "0x1",
            "yParity": "0x1",
            "chainId": "0x1",
            "accessList": [],
            "type": "0x2"
        }
    }
}

Official SDKs

An alternative way to subscribe the transactions stream is to use our official SDKs, released in different programming languages. In this scenario transactions are pushed as a stream of RLP (Recursive Length Prefix) encoded bytes. This is the raw format transactions used by our worldwide network.

The RLP WebSocket endpoint structure is the following

wss://txs.merkle.io/ws/{api-key}/{chain-id}

SDKs and their relative documentation are available here

Last updated