{"path":"lib/solana-confirm.js","size":1864,"locked":false,"binary":false,"truncated":false,"content":"/**\n * Sends and confirms a transaction WITHOUT relying on WebSocket signature\n * subscriptions (the default confirmation strategy in @solana/web3.js's\n * sendAndConfirmTransaction).\n *\n * CONFIRMED NEEDED via live devnet testing: some RPC providers (confirmed:\n * Alchemy's devnet endpoint) don't support the `signatureSubscribe` RPC\n * method, so the library's built-in confirmation hangs on repeated\n * \"Method not found\" errors and eventually times out with\n * TransactionExpiredBlockheightExceededError — even when the transaction\n * actually landed on-chain. Polling via getSignatureStatus works with any\n * RPC provider regardless of WebSocket support, so this is used everywhere\n * a transaction needs confirming (lib/sns.js and scripts/devnet-test.js)\n * instead of the library default.\n */\nexport async function sendAndConfirm(connection, transaction, signers) {\n  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();\n  transaction.recentBlockhash = blockhash;\n  transaction.feePayer = signers[0].publicKey;\n  transaction.sign(...signers);\n\n  const signature = await connection.sendRawTransaction(transaction.serialize());\n\n  const start = Date.now();\n  while (Date.now() - start < 60_000) {\n    const { value } = await connection.getSignatureStatus(signature);\n    if (value?.err) {\n      throw new Error(`Transaction failed: ${JSON.stringify(value.err)}`);\n    }\n    if (value?.confirmationStatus === 'confirmed' || value?.confirmationStatus === 'finalized') {\n      return signature;\n    }\n    const blockHeight = await connection.getBlockHeight();\n    if (blockHeight > lastValidBlockHeight) {\n      throw new Error(`Transaction expired before confirmation: ${signature}`);\n    }\n    await new Promise((resolve) => setTimeout(resolve, 2000));\n  }\n  throw new Error(`Confirmation timed out after 60s: ${signature}`);\n}\n"}