diff --git a/hederaBlockchainAPI.js b/hederaBlockchainAPI.js index 7518108..3e6bb28 100644 --- a/hederaBlockchainAPI.js +++ b/hederaBlockchainAPI.js @@ -290,7 +290,7 @@ /** * Send HBAR using JSON-RPC Relay (EVM-compatible) * @param {string} fromPrivateKey - Sender's private key (hex format) - * @param {string} toAddress - Recipient's EVM address + * @param {string} toAddress - Recipient's EVM address (0x...) - Account IDs should be converted to EVM addresses before calling * @param {number} amount - Amount in HBAR * @param {string} memo - Optional memo * @returns {Promise} - Transaction result diff --git a/index.html b/index.html index 2e7415c..58c6372 100644 --- a/index.html +++ b/index.html @@ -355,7 +355,7 @@ -
Enter an HBAR address or BTC/FLO/HBAR private key to view transactions
+
Enter EVM address, Account ID or BTC/FLO/HBAR private key to view transactions
@@ -562,12 +562,12 @@
- +
-
EVM address format (0x...)
+
EVM address (0x...) or Account ID (0.0.xxxx)
@@ -1597,21 +1597,37 @@ return; } - if (!recipient.startsWith('0x') || recipient.length !== 42) { - showNotification('⚠️ Invalid recipient address. Expected EVM address (0x...)', 'error'); + // Validate recipient address format (EVM or Account ID) + const validation = hederaAPI.validateAddress(recipient); + if (!validation.valid) { + showNotification('⚠️ Invalid recipient address. Expected EVM address (0x...) or Account ID (0.0.xxxx)', 'error'); return; } + // If Account ID is provided, convert it to EVM address + let recipientEvmAddress = recipient; + if (validation.type === 'accountId') { + try { + showNotification('🔄 Converting Account ID to EVM address...', 'info'); + const accountData = await hederaAPI.getBalance(recipient); + recipientEvmAddress = accountData.evmAddress; + console.log(`Converted Account ID ${recipient} to EVM address ${recipientEvmAddress}`); + } catch (error) { + showNotification('⚠️ Could not find account. Please verify the Account ID.', 'error'); + return; + } + } + if (!amount || amount <= 0) { showNotification('⚠️ Please enter a valid amount', 'warning'); return; } try { - // Check if recipient account exists + // Check if recipient account exists (using EVM address) let recipientExists = false; try { - const recipientBalance = await hederaAPI.getBalance(recipient); + const recipientBalance = await hederaAPI.getBalance(recipientEvmAddress); recipientExists = true; console.log('Recipient account exists with balance:', recipientBalance.balance); } catch (error) { @@ -1643,11 +1659,13 @@ const gasPrice = await web3.eth.getGasPrice(); console.log('Current gas price:', gasPrice, 'wei'); - // Estimate gas for this transaction - const amountInWei = web3.utils.toWei(amount.toString(), 'ether'); + // Estimate gas for this transaction (use EVM address) + + const amountString = amount.toFixed(18); + const amountInWei = web3.utils.toWei(amountString, 'ether'); const estimatedGas = await web3.eth.estimateGas({ from: senderAddress, - to: recipient, + to: recipientEvmAddress, value: amountInWei }); console.log('Estimated gas units:', estimatedGas); @@ -1678,12 +1696,12 @@ return; } - // Store pending transaction + // Store pending transaction (use EVM address) const estimatedFee = estimatedGasFee; pendingTx = { privateKey: hexPrivateKey, // Use hex format for API from: senderAddress, - to: recipient, + to: recipientEvmAddress, // Use EVM address for transaction amount: amount, fee: estimatedFee, total: amount + estimatedFee