/**
 * Basic usage example: Connect to ChainID 138 and query chain data
 */

import { initTatumSDK, verifyConnection } from '../tatum-client';
import { CHAIN_ID, CHAIN_NAME } from '../config';

async function main() {
  console.log(`Connecting to ${CHAIN_NAME} (ChainID ${CHAIN_ID})...`);
  
  // Initialize Tatum SDK with custom RPC URL
  const tatum = await initTatumSDK({
    rpcUrl: process.env.RPC_URL || 'http://localhost:8545',
    verbose: true,
  });
  
  // Verify connection and chain ID
  console.log('\n=== Verifying Connection ===');
  const connectionInfo = await verifyConnection(tatum);
  console.log('Connection verified!');
  console.log(`Chain ID: ${connectionInfo.chainId} (${connectionInfo.chainIdHex})`);
  console.log(`Current Block: ${connectionInfo.blockNumber}`);
  console.log(`Network Version: ${connectionInfo.netVersion}`);
  console.log(`Syncing: ${connectionInfo.syncing}`);
  
  // Query additional chain data
  console.log('\n=== Querying Chain Data ===');
  
  // Get latest block
  const latestBlock = await tatum.rpc.request('eth_getBlockByNumber', ['latest', false]);
  console.log('Latest Block:', JSON.stringify(latestBlock, null, 2));
  
  // Get gas price
  const gasPrice = await tatum.rpc.request('eth_gasPrice', []);
  console.log('Gas Price:', gasPrice);
  
  // Get peer count
  const peerCount = await tatum.rpc.request('net_peerCount', []);
  console.log('Peer Count:', peerCount);
  
  // Get balance of an address (example)
  const exampleAddress = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb';
  const balance = await tatum.rpc.request('eth_getBalance', [exampleAddress, 'latest']);
  console.log(`Balance of ${exampleAddress}:`, balance);
  
  console.log('\n=== Basic Usage Example Complete ===');
}

main().catch((error) => {
  console.error('Error:', error);
  process.exit(1);
});

