Contracts whisper events—listen up! 👂 Use SDK for targeted streams.
In this example we are using VTHO contract address (0x0000000000000000000000000000456e65726779).
import { subscriptions } from '@vechain/sdk-network';
import WebSocket from 'ws';
const wsUrl = subscriptions.getEventLogsSubscriptionUrl('https://mainnet.vechain.org', {
address: '0x0000000000000000000000000000456e65726779',
topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
});
const ws = new WebSocket(wsUrl);
ws.onmessage = (msg) => {
const logs = JSON.parse(msg.data);
console.log('VTHO Transfer:', logs);
};import { subscriptions } from '@vechain/sdk-network';
import WebSocket from 'ws';
const wsUrl = subscriptions.getEventLogsSubscriptionUrl('https://mainnet.vechain.org', {
address: '0x0000000000000000000000000000456e65726779',
topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
});
const ws = new WebSocket(wsUrl);
ws.onmessage = (msg) => {
const logs = JSON.parse(msg.data);
console.log('VTHO Transfer:', logs);
};import { subscriptions } from '@vechain/sdk-network';
import WebSocket from 'ws';
const wsUrl = subscriptions.getEventLogsSubscriptionUrl('https://mainnet.vechain.org', {
address: '0x0000000000000000000000000000456e65726779',
topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
});
const ws = new WebSocket(wsUrl);
ws.onmessage = (msg) => {
const logs = JSON.parse(msg.data);
console.log('VTHO Transfer:', logs);
};Multi-connect: Open separate WS for events + blocks. No polling needed!
Ears open!
No ABI? Can't decode—fetch from b32.
Another perk for you, the topic you find in the example above is common to ALL ERC20 tokens!