@prathammahajan/blockchain-integration
Version:
🚀 Comprehensive blockchain integration suite with multi-chain cryptocurrency support, NFT marketplace, smart contracts, DeFi protocols, and enterprise-grade wallet management
76 lines (61 loc) • 2.14 kB
JavaScript
const BlockchainEngine = require('../src/index');
async function transactionMonitoringExample() {
try {
// Initialize blockchain engine
const blockchain = new BlockchainEngine({
networks: {
ethereum: {
enabled: true,
rpc: 'https://mainnet.infura.io',
chainId: 1
}
},
wallet: {
enabled: true,
encryption: true
}
});
// Wait for initialization
await new Promise(resolve => {
blockchain.on('initialized', resolve);
});
console.log('✅ Blockchain Engine initialized');
// Create a wallet
const wallet = await blockchain.createWallet('hd');
console.log('✅ Wallet created:', wallet.address);
// Set up transaction monitoring
blockchain.on('transactionSent', (data) => {
console.log('📤 Transaction sent:', data.txHash);
});
blockchain.on('transactionUpdate', (data) => {
console.log('📊 Transaction update:', data.txHash, data.status);
});
blockchain.on('transactionConfirmed', (data) => {
console.log('✅ Transaction confirmed:', data.txHash);
});
blockchain.on('transactionFailed', (data) => {
console.log('❌ Transaction failed:', data.txHash, data.error);
});
// Send a transaction
const txResult = await blockchain.sendTransaction(
wallet.walletId,
'0xrecipient',
'1.0',
'ethereum'
);
console.log('✅ Transaction sent:', txResult.txHash);
// Monitor transaction status
const status = await blockchain.getTransactionStatus(txResult.txHash, 'ethereum');
console.log('✅ Transaction status:', status);
// Get transaction history
const history = await blockchain.getTransactionHistory(wallet.walletId, 'ethereum');
console.log('✅ Transaction history:', history);
// Shutdown
await blockchain.shutdown();
console.log('✅ Blockchain Engine shutdown');
} catch (error) {
console.error('❌ Error:', error.message);
}
}
// Run the example
transactionMonitoringExample();