# Transactions

## Connection

The connection is managed using WebSockets, which connect directly to a VeChain node.

A simple connection can be established with this snippet:

```js
import WebSocket from 'ws';
const ws = new WebSocket('wss://mainnet.vechain.org/subscriptions/txpool');
ws.onmessage = (message) => {
    console.log('New pending transaction', message.data);
}
```

This will receive all new entries added to the transaction pool in the form of JSON-encoded strings.

Subscriptions only receive the transaction ID as soon as it is added to the transaction pool. A transaction may either be successfully included in a block, reverted, or expire in the future.

To obtain detailed information about a transaction, you will need to make a second request, either directly from the node or by using a Thor client.

```js
await fetch(`https://mainnet.vechain.org/transactions/${txId}?pending=true`).then(res => res.json())
```

```js
const tx = await thor.transactions.getTransaction(addedTx.id, {
  pending: true,
});
```

## Example Project

{% embed url="<https://stackblitz.com/github/vechain-energy/example-snippets/tree/v1.0.0/sdk/listen-transactions?ctl=1&embed=1&file=index.mjs&hideExplorer=1&hideNavigation=1&view=editor>" %}


---

# 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.vechain.org/developer-resources/how-to-build-on-vechain/listen-to-changes/transactions.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.
