Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
strykerin committed Feb 11, 2025
1 parent 0df8ad0 commit 9e8a5e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 17 additions & 13 deletions examples/fetch-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
3 changes: 2 additions & 1 deletion examples/send-transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -42,4 +43,4 @@ const tx = await pushChain.tx.send(
}
);

console.log(tx.txHash);
console.log('Transaction sent successfully! Transaction hash:', tx.txHash);

0 comments on commit 9e8a5e8

Please sign in to comment.