# Events

To create a client application that receives real-time notifications for transactions (BSV, Token, and NFT), we will use the socket.io-client package. This document provides a step-by-step guide for implementing this functionality.

#### Step 1: User Authentication

The first step is to authenticate the user by making a request to the "/v1/login" endpoint. This is a necessary step to ensure that only authorized users can receive transaction notifications.

#### Step 2: Event Listening

The next step is to set up the client application to listen for specific events in order to receive relevant messages and data. The following events can be listened for:

* "notification": To receive transactional notifications.
* "balance": To receive updates on balance changes.
* "history": To receive updates on history changes.

Here is an example of how to implement event listening in your client application:

```
const { io } = require('socket.io-client')
            
const relysiaEndpoint = 'https://api.enterprise.relysia.com/';

(async () => {
    // Connect websocket for this account
    const socket = io(relysiaEndpoint, {
        auth: {
            serviceid: serviceid
            authToken: token
        }
    });

    socket.on('error', function(error) {
        console.log("Connection Error: " + error.toString());
    });

    // Listen for message and log them as notification arrive
    socket.on('notification', function (message) {
        console.log('Notification received:', message);
    })

    // Listen for balance and log them on balance arrive
    socket.on('balance', function (balance) {
        console.log('Balance update received:', balance);
    })

    // Listen for history and log them on history arrive
    socket.on('history', function (history) {
        console.log('History update received:', history);
    })
    
    socket.on('connect', function(connection) {
        console.log('WebSocket Client Connected');
        socket.on('close', function() {
            console.log('Connection Closed');
        });
    });
})()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.relysia.com/enterprise-wallet/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
