Transactions

Connection

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

A simple connection can be established with this snippet:

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.

await fetch(`https://mainnet.vechain.org/transactions/${txId}?pending=true`).then(res => res.json())
const tx = await thor.transactions.getTransaction(addedTx.id, {
  pending: true,
});

Example Project

Last updated