Blockchain Query

Select a query type and enter the corresponding identifier to explore the Ethereum Sepolia testnet.

Fetching data...

Exploration Results

No transactions in this block or data unavailable for all.

'}
`; } break; case 'transactionHash': if (!/^0x([A-Fa-f0-9]{64})$/.test(query)) { errorDisplay.textContent = 'Error: Invalid transaction hash format. Must be a 0x-prefixed 64-character hex string.'; errorDisplay.style.display = 'block'; return; } data = await bce_fetchFromRPC('eth_getTransactionByHash', [query]); if (data) { const receipt = await bce_fetchFromRPC('eth_getTransactionReceipt', [query]); resultsTitle.textContent = `Transaction Details: ${data.hash.substring(0,12)}...`; resultsContainer.innerHTML = `
${bce_renderResultItem('Transaction Hash', data.hash)} ${bce_renderResultItem('Block Number', bce_hexToDecimal(data.blockNumber))} ${bce_renderResultItem('Block Hash', data.blockHash)} ${bce_renderResultItem('From', data.from)} ${bce_renderResultItem('To', data.to || 'N/A (Contract Creation?)')} ${bce_renderResultItem('Value', `${bce_weiToEth(data.value)} ETH` , true)} ${bce_renderResultItem('Gas Price', `${bce_weiToEth(data.gasPrice)} ETH (${bce_hexToDecimal(data.gasPrice)} Wei)` , true)} ${bce_renderResultItem('Gas Limit (Provided)', bce_hexToDecimal(data.gas))} ${receipt ? bce_renderResultItem('Gas Used by Tx', bce_hexToDecimal(receipt.gasUsed)) : ''} ${receipt ? bce_renderResultItem('Status', receipt.status === '0x1' ? 'Success' : 'Failed (Reverted)', true) : ''} ${bce_renderResultItem('Nonce', bce_hexToDecimal(data.nonce))} ${bce_renderResultItem('Input Data', data.input.length > 100 ? data.input.substring(0,100) + '...' : data.input)}
`; } break; case 'address': if (!/^0x([A-Fa-f0-9]{40})$/.test(query)) { errorDisplay.textContent = 'Error: Invalid address format. Must be a 0x-prefixed 40-character hex string.'; errorDisplay.style.display = 'block'; return; } const balance = await bce_fetchFromRPC('eth_getBalance', [query, 'latest']); const transactionCount = await bce_fetchFromRPC('eth_getTransactionCount', [query, 'latest']); // eth_getCode for checking if it's a contract (returns '0x' for EOA) const code = await bce_fetchFromRPC('eth_getCode', [query, 'latest']); if (balance !== null && transactionCount !== null && code !== null) { // Ensure all crucial calls succeeded const isContract = code !== '0x' && code !== null && code.length > 2; resultsTitle.textContent = `Address Details: ${query.substring(0,10)}...`; resultsContainer.innerHTML = `
${bce_renderResultItem('Address', query)} ${bce_renderResultItem('Balance', `${bce_weiToEth(balance)} ETH`, true)} ${bce_renderResultItem('Transaction Count (Nonce)', bce_hexToDecimal(transactionCount), true)} ${bce_renderResultItem('Type', isContract ? 'Contract' : 'Externally Owned Account (EOA)', true)} ${isContract ? bce_renderResultItem('Contract Code', code.length > 100 ? code.substring(0,100) + '... (truncated)' : code) : ''}

Note: Transaction history for addresses is not displayed in this basic explorer.

`; } else { // Error already handled by bce_fetchFromRPC if one of them failed and set errorDisplay if (!errorDisplay.textContent) { // If no specific error was set by fetch but data is incomplete errorDisplay.textContent = 'Error: Could not retrieve all details for the address.'; errorDisplay.style.display = 'block'; } } break; default: errorDisplay.textContent = 'Error: Invalid query type selected.'; errorDisplay.style.display = 'block'; return; } if (data || (type === 'address' && balance !== null)) { // For address, balance is a good indicator if any data was fetched // Switch to results tab const resultsTabButton = Array.from(document.querySelectorAll('#bce-container .bce-tab-button')).find(btn => btn.textContent.includes("Exploration Results")); if(resultsTabButton) resultsTabButton.click(); } else if (!errorDisplay.textContent && !data) { // If no data and no error already shown errorDisplay.textContent = 'No data found for the given query, or the resource does not exist on the Sepolia testnet.'; errorDisplay.style.display = 'block'; } } function bce_generatePDF() { const { jsPDF } = window.jspdf; const pdfOutputArea = document.getElementById('bce-pdf-output-area'); const resultsContainer = document.getElementById('bce-resultsContainer'); const loader = document.getElementById('bce-loader'); // Use existing loader if (!window.jspdf || !window.html2canvas) { alert('PDF generation library not loaded. Please check your internet connection.'); return; } if (!pdfOutputArea || !resultsContainer) { alert('PDF output area not found.'); return; } if (resultsContainer.innerHTML.trim() === "") { alert('Please perform an exploration first to generate results for the PDF.'); return; } if (loader) { loader.innerHTML = '
Generating PDF...'; loader.style.display = 'block'; } html2canvas(pdfOutputArea, { scale: 2, useCORS: true, backgroundColor: '#ffffff' }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const margin = 40; // 20pt margin on each side = 40 total width reduction let imgRenderWidth = pdfWidth - margin; let imgRenderHeight = (canvasHeight * imgRenderWidth) / canvasWidth; let heightLeft = imgRenderHeight; let position = margin / 2; // Initial Y position (top margin) pdf.addImage(imgData, 'PNG', margin / 2, position, imgRenderWidth, imgRenderHeight); heightLeft -= (pdfHeight - margin); // Subtract first page height (with margins) while (heightLeft > 0) { position = heightLeft - imgRenderHeight; // This calculation seems off for new page y position. // It should be negative of total height rendered so far. pdf.addPage(); pdf.addImage(imgData, 'PNG', margin / 2, position - (margin/2), imgRenderWidth, imgRenderHeight); // Adjust Y to map the correct part of canvas heightLeft -= (pdfHeight - margin); } pdf.save('Blockchain_Exploration_Results.pdf'); if (loader) { loader.innerHTML = '
Fetching data...'; // Reset loader text loader.style.display = 'none'; } }).catch(err => { console.error("BCE Error generating PDF:", err); alert("Error generating PDF. See console for details."); if (loader) { loader.innerHTML = '
Fetching data...'; loader.style.display = 'none'; } }); } // Initialize first tab & nav buttons on load window.addEventListener('load', () => { const firstTabButton = document.querySelector('#bce-container .bce-tab-button.active'); if(firstTabButton) { const tabId = firstTabButton.getAttribute('onclick').match(/'([^']+)'/)[1]; const firstTabContent = document.getElementById(tabId); if (firstTabContent) { document.querySelectorAll('#bce-container .bce-tab-content').forEach(tc => tc.style.display = 'none'); firstTabContent.style.display = 'block'; firstTabContent.classList.add('active'); } } bce_updateNavButtons(); bce_updateInputPlaceholder(); // Ensure correct placeholder on load });
Scroll to Top