VET Transfers
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/transfer');
ws.onmessage = (message) => {
console.log('New transfer', message.data);
}This will receive all transfers on the blockchain as JSON-encoded strings.
Filter Specific Transfers
The VeChain SDK facilitates the construction of filters to retrieve only the desired data by generating a subscription URL with specified parameters. Using the subscriptions helper, you can create a custom subscription URL that listens exclusively to the specified event.
All options are optional, and a transfer must match all specified criteria:
const wsUrl = subscriptions.getVETtransfersSubscriptionUrl(
'https://mainnet.vechain.org',
{
blockID: undefined, // block id to start from, defaults to the best block.
signerAddress: undefined, // The address of the signer/origin of the transaction to filter transfers by.
sender: undefined, // The sender address to filter transfers by.
recipient: undefined, // The recipient address to filter transfers by.
}
);Transfer Details
The transfers are received as JSON-encoded strings. These strings must be parsed into usable objects, resulting in an object of type TransferLogs.
An example result is:
The amount is a hexlified BigInt that can be converted into a BigInt using BigInt(transferLog.amount).
Example Project
Last updated
Was this helpful?