Learn how to connect with Polygon WebSocket.
Supported WebSocket Methods
The Blockdaemon RPC API supports the following methods:
Event types
The WebSocket requests can subscribe to the following event types:
Types | Description |
---|---|
alchemy_minedTransactions | Subscribes to mined transactions and filters based on specified addresses. |
alchemy_pendingTransactions | Subscribes to pending transactions and filters based on specified from and/or to addresses. |
newPendingTransactions | Subscribes to all pending transactions. |
newHeads | Emits events for new block headers. |
logs | Emit logs match the specified topics included in new blocks. |
How To Access
Step 1: Authorize your request. Learn more: Authentication Guide
--headers 'Authorization: Bearer YOUR_API_KEY'
Step 2: Use the following WebSocket URL:
wss://svc.blockdaemon.com/:protocol/:network/native?service_name=:service
Step 3: Specify an Ethereum method in the request body:
jsonrpc
: Always "2.0".id
(int64): request ID.method
: Ethereum RPC WebSocket method. Such aseth_subscribe
.params
:
├──Event types
: The type of event to listen to (refer to Event types)
└──Optional params
: Optional parameters to describe the type of event to listen to (e.g.,address
)
For example, this request creates a new subscription for desired events.
--headers 'Authorization: Bearer YOUR_API_KEY' \
wss://svc.blockdaemon.com/polygon/mainnet/native?service_name=ws \
'{"jsonrpc":"2.0","id": 2, "method": "eth_subscribe", "params": ["logs"]}'
Step 4: It will return a response containing the subscription ID (subscription
). It is included in all notifications and is required when unsubscribing.
jsonrpc
: Always "2.0"method
: Indicates that this response is related to an Ethereum subscription.params
:
├──result
: Object contains details about the transaction, including its hash.subscription
The subscription ID associated with this response.
{
"jsonrpc":"2.0",
"method":"eth_subscription",
"params": {
"subscription":"0x4a8a4c0517381924f9838102c5a4dcb7",
"result":{
"address":"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd",
"blockHash":"0x61cdb2a09ab99abf791d474f20c2ea89bf8de2923a2d42bb49944c8c993cbf04",
"blockNumber":"0x29e87",
"data":"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003",
"logIndex":"0x0",
"topics":["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"],
"transactionHash":"0xe044554a0a55067caafd07f8020ab9f2af60bdfe337e395ecd84b4877a3d1ab4",
"transactionIndex":"0x0"
}
}
}
👋 Need Help?
Contact us through email or our support page for any issues, bugs, or assistance you may need.