// Replace <api-key> with your Helius API key
const { Connection } = require('@solana/web3.js');
async function getConfirmedSlot() {
const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
try {
const slot = await connection.getSlot('confirmed');
console.log('Current slot (confirmed commitment):', slot);
// Note: For @solana/web3.js v1.30.0 and later, you can pass commitment directly.
// For older versions or more complex options, use an object:
// const slot = await connection.getSlot({ commitment: 'confirmed' });
} catch (error) {
console.error('Error fetching confirmed slot:', error);
}
}
getConfirmedSlot();