I am new to Sol web3 dev. I am trying to get pending transactions of a wallet. When I try to get the block, it fails with error "SolanaJSONRPCError: failed to get confirmed block: Block not available for slot " Could somebody help me? Here is my code snippet and it fails at getBlock or getConfirmedBlock methods.
const connection = new Connection('https://api.mainnet-beta.solana.com'); // Use the appropriate network
async function copyPendingTrades() {// Subscribe to new blocksconst subscription = connection.onSlotChange(async (slotInfo) => {// Fetch all transactions in the latest blockconst blockhash = await connection.getRecentBlockhash();const confirmedTransactions = await connection.getConfirmedBlock(slotInfo.slot);const unconfirmedTransactions = await connection.getBlock(slotInfo.slot);
// Extract unconfirmed transactionsconst pendingTransactions = unconfirmedTransactions.transactions.filter( (tx) => !confirmedTransactions.transactions.some((confirmedTx) => confirmedTx.transaction.signature === tx.transaction.signature));