From 9e8a5e846e17886eb28053a69837702eee866600 Mon Sep 17 00:00:00 2001 From: strykerin Date: Tue, 11 Feb 2025 09:26:17 -0300 Subject: [PATCH] improve logging --- examples/fetch-blocks/index.js | 30 +++++++++++++++++------------- examples/send-transaction/index.js | 3 ++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/fetch-blocks/index.js b/examples/fetch-blocks/index.js index 476a11fd..122e9f7c 100644 --- a/examples/fetch-blocks/index.js +++ b/examples/fetch-blocks/index.js @@ -3,25 +3,29 @@ import { CONSTANTS, PushChain } from '@pushchain/devnet'; // Initialize the Push Chain SDK const pushChain = await PushChain.initialize(); +console.log('PushChain SDK initialized successfully for block operations.'); // Fetch block by hash -const blockByHash = await pushChain.block.get( - '28ca25bb8a0b59b76612bcef411984d60f28d0468676fc755ed8f946433d0c64' -); - -console.log(blockByHash); +const blockHash = + '28ca25bb8a0b59b76612bcef411984d60f28d0468676fc755ed8f946433d0c64'; +const blockByHash = await pushChain.block.get(blockHash); +console.log(`Fetched block by hash (${blockHash}):`, blockByHash); -// Fetch the latest 20 blocks +// Fetch the latest 5 blocks const latestBlocks = await pushChain.block.get('*', { - limit: 20, + limit: 5, }); - -console.log(latestBlocks); +console.log('Fetched the latest 20 blocks:', latestBlocks); // Fetch blocks by dates - yesterday -const blockByData = await pushChain.block.get('*', { - startTime: Math.floor(Date.now() - 24 * 60 * 60 * 1000), +const startTime = Math.floor(Date.now() - 24 * 60 * 60 * 1000); +const blockByDate = await pushChain.block.get('*', { + startTime: startTime, order: 'ASC', }); - -console.log(blockByData); +console.log( + `Fetched blocks from yesterday (starting at ${new Date( + startTime + ).toISOString()}):`, + blockByDate +); diff --git a/examples/send-transaction/index.js b/examples/send-transaction/index.js index 25d6dcaf..66762d40 100644 --- a/examples/send-transaction/index.js +++ b/examples/send-transaction/index.js @@ -23,6 +23,7 @@ const signer = { // Initialize Push Chain SDK const pushChain = await PushChain.initialize(signer); +console.log('PushChain SDK initialized.'); // Send Transaction const tx = await pushChain.tx.send( @@ -42,4 +43,4 @@ const tx = await pushChain.tx.send( } ); -console.log(tx.txHash); +console.log('Transaction sent successfully! Transaction hash:', tx.txHash);