Subscribes to a specific type of event and returns the subscription ID in the response. For each event that matches the subscription, a notification with the relevant data is sent along with the subscription ID.
wss://api.zan.top/node/ws/v1/xlayer/mainnet/{apiKey}
Request Parameters
- SUBSCRIPTION EVENT: specifies the type of events you want to subscribe to. Valid values:
- newHeads: returns a notification each time a new block header is appended to the chain, including those generated from chain reorganizations. In case of a chain reorganization, the subscription emits all new block headers for the new chain. Therefore, a subscription could emit block headers at the same height multiple times.
- logs: returns logs that are included in the newly added blocks and match the given filter. In case of a chain reorganization, the previously emitted logs on the old chain are re-emitted with the
removed
property set to true. Logs from transactions in the new chain are emitted. Therefore, a subscription could emit logs for the same transaction multiple times.- address - [Optional] An address or an array of addresses. Only logs that are created from these addresses are returned.
- topics - [Optional] Only records logs that match the specified topics.
- newPendingTransactions: returns hashes for all transactions that are added to the pending state and signed with keys available in the node (a hash for each transaction). In case of a chain reorganization, some transactions that were originally on the canonical chain may be excluded from the new canonical chain because they are included in other chains. In this case, these transactions are added to the pending state again. Therefore, a subscription can emit logs for the same transaction multiple times.
Response
The subscription ID.
Result Fields
- SUBSCRIPTION ID: the ID of the newly created subscription.
Examples
Example Requests
## JSON-RPC over WSS
## Replace {apiKey} with the API key you obtained from the ZAN dashboard.
## You can also replace the mainnet with any other supported networks.
wscat -c wss://api.zan.top/node/ws/v1/xlayer/mainnet/{apiKey}
> {"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads"]}
> {"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
> {"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["logs", {"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}
Example Responses
{
"result": "87be5b00-608c-45fd-a66a-f5df5e5508d3",
"session": "03b13a6f-eb29-4720-9c43-c22a7e5c0ae3",
"id": 1,
"jsonrpc": "2.0"
}