Soy nuevo en este negocio, así que me disculpo por una pregunta tan posiblemente básica y estúpida, intenté encontrar cualquier información, pero no pude.
Hice una serie de transferencias a la dirección que se muestra en el siguiente ejemplo.
También tengo estas transferencias en mi historia, y están marcadas como exitosas. Como referencia, hice una transferencia de mi billetera a la dirección que está vinculada a mi billetera.
También tengo una conexión a la crimson de pruebas.
En la billetera, como se muestra, todo está ahí, todo está bien, pero cuando intentas verificar la información de mi dirección, no hay nada allí.
Aquí revisé la dirección a través de un sitio especial.
Escribí un pequeño programa para verificar el historial de la dirección, el equilibrio, pero no se muestra nada allí.
Connecting to Electrum server...
Efficiently related to Electrum server.
Deal with: tb1qc7j5j80s02gupl0qa3svg5kr99smjdq9a7yezd
ScriptHash: bb72dcabbea723d56aa49cd29575e53aaabf832f9dbdb45f251b56e187ce915a
Uncooked historical past response: ()
Fetching transaction historical past...
Discovered 0 transactions.
Whole steadiness for tb1qc7j5j80s02gupl0qa3svg5kr99smjdq9a7yezd: 0 satoshis (0 BTC)
Present block peak: 900621
Disconnected from Electrum server.
Aquí está el código del programa en sí:
import * as bitcoin from 'bitcoinjs-lib';
import { ElectrumClient, ElectrumClientEvents } from '@electrum-cash/community';
const ELECTRUM_HOST = 'blackie.c3-soft.com';
const ADDRESS = 'tb1qc7j5j80s02gupl0qa3svg5kr99smjdq9a7yezd';
const NETWORK = bitcoin.networks.testnet;
perform addressToElectrumScriptHash(handle: string, community: bitcoin.Community): string | null {
strive {
const outputScript = bitcoin.handle.toOutputScript(handle, community);
const hash = bitcoin.crypto.sha256(outputScript);
return Buffer.from(hash.reverse()).toString('hex');
} catch (e) {
console.error(`Did not convert handle ${handle} to scripthash: ${e.message}`);
return null;
}
}
async perform debugScripthashHistory(consumer: ElectrumClient<ElectrumClientEvents>, scriptHash: string) {
strive {
const historical past = await consumer.request('blockchain.scripthash.get_history', scriptHash);
console.log('Uncooked historical past response:', JSON.stringify(historical past, null, 2));
} catch (error) {
console.error('Error fetching uncooked historical past:', error.message);
}
}
async perform checkAddress() {
const consumer = new ElectrumClient(
'Deal with Checker',
'1.4.1',
ELECTRUM_HOST,
);
strive {
console.log('Connecting to Electrum server...');
await consumer.join();
console.log('Efficiently related to Electrum server.');
const scriptHash = addressToElectrumScriptHash(ADDRESS, NETWORK);
if (!scriptHash) {
console.error('Did not generate scripthash for handle.');
return;
}
console.log(`Deal with: ${ADDRESS}`);
console.log(`ScriptHash: ${scriptHash}`);
await debugScripthashHistory(consumer, scriptHash);
console.log('Fetching transaction historical past...');
const historyResult = await consumer.request('blockchain.scripthash.get_history', scriptHash);
if (historyResult instanceof Error) {
console.error(`Error fetching historical past: ${historyResult.message}`);
return;
}
if (!Array.isArray(historyResult)) {
console.error('Sudden historical past response:', historyResult);
return;
}
const historical past = historyResult as { tx_hash: string; peak: quantity }();
console.log(`Discovered ${historical past.size} transactions.`);
let totalBalance = 0;
for (const tx of historical past) {
const txHash = tx.tx_hash;
console.log(`Processing transaction: ${txHash} (Block peak: ${tx.peak})`);
const txDataResult = await consumer.request('blockchain.transaction.get', txHash, true);
if (txDataResult instanceof Error) {
console.error(`Error fetching transaction ${txHash}: ${txDataResult.message}`);
proceed;
}
if (!txDataResult || typeof txDataResult !== 'object') {
console.error(`Invalid transaction knowledge for ${txHash}`);
proceed;
}
const txData = txDataResult as { vout: { worth: string; scriptPubKey: { hex: string } }() };
const outputScriptHex = bitcoin.handle.toOutputScript(ADDRESS, NETWORK).toString('hex');
for (const vout of txData.vout) {
if (vout.scriptPubKey.hex === outputScriptHex) {
const quantity = Math.spherical(parseFloat(vout.worth) * 1e8); // Конвертация BTC в сатоши
totalBalance += quantity;
console.log(`Discovered output to deal with: ${quantity} satoshis`);
}
}
}
console.log(`Whole steadiness for ${ADDRESS}: ${totalBalance} satoshis (${totalBalance / 1e8} BTC)`);
const blockHeightResponse = await consumer.request('blockchain.headers.subscribe');
if (blockHeightResponse && typeof blockHeightResponse === 'object' && 'peak' in blockHeightResponse) {
console.log(`Present block peak: ${blockHeightResponse.peak}`);
}
} catch (error) {
console.error('Error throughout handle test:', error.message);
} lastly {
strive {
await consumer.disconnect();
console.log('Disconnected from Electrum server.');
} catch (e) {
console.error('Error throughout disconnection:', e.message);
}
}
}
checkAddress().catch(console.error);