Skip to content

Commit

Permalink
ALL-5473 - Fix solana mainnet tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Mar 7, 2024
1 parent 278e69f commit cebae2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tatumio",
"version": "2.2.58",
"version": "2.2.59",
"license": "MIT",
"repository": "https://github.com/tatumio/tatum-js",
"scripts": {
Expand Down
13 changes: 9 additions & 4 deletions packages/blockchain/solana/src/lib/services/solana.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,21 @@ export const solanaUtils = {
})
},
sendTransactionWithConfirm: async (connection: Connection, transaction: Transaction, signers: Signer[]) => {
const attempts = 5
const attempts = 10
const txId = await connection.sendTransaction(transaction, signers)
let confirmedTx
for (let attempt = 1; attempt <= attempts; attempt++) {
const confirmedTx = await connection.getTransaction(txId, { commitment: 'confirmed' })

confirmedTx = await connection.getTransaction(txId, { commitment: 'confirmed' })
if (confirmedTx && !confirmedTx.meta?.err) {
return { txId }
}
await new Promise((r) => setTimeout(r, 500))
await new Promise((r) => setTimeout(r, attempt * 1000))
}

if (confirmedTx && confirmedTx.meta?.err) {
throw new Error(`Transaction failed with error: ${confirmedTx.meta?.err}`)
}

throw new Error(
`Transaction not confirmed after ${attempts} attempts, please try to send transaction again.`,
)
Expand Down

0 comments on commit cebae2e

Please sign in to comment.