Developer Fundamentals
-- II. VET Transfers
Learn how to use WebSockets and filters to listen to live VET transfers on VeChainThor and decode the transfer data.
Listening to VET Transfers
This lesson will take you through the most important information about how to listen to specific VET transfers and how to decode the transfer details.
Similar to other listening methods, you'll first need to establish a direct connection with a VeChain node.
The connection is managed using WebSockets, which connect directly to a VeChain node.
How To Establish a Direct Connection
A simple connection can be established with this snippet:
This will receive all transfers on the blockchain as JSON-encoded strings.
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:
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).
Try It Yourself
The snippet below listens to VET Transfers from a specified sender address. Try adding other filters and inspect the different responses.
Join our Telegram