I wrote a function in typescript by using solana/web3.js
. Sometimes, I received this error. I simply implement code following the doc of solana. I realized if I use sendRawTransaction
, it will be better result, the failure percentage is quite lower than sendTransaction
.
const amount = this.convertSOL2LAMPORT(request.amount).toNumber()
const transaction = new solanaWeb3.Transaction().add(
solanaWeb3.SystemProgram.transfer({
fromPubkey: signerKeyPair.publicKey,
toPubkey: new solanaWeb3.PublicKey(request.to),
lamports: amount,
}),
)
const result = await this.provider.sendTransaction(
transaction,
[signerKeyPair],
{
/**
* * Base on retry transaction fact
* * https://solanacookbook.com/guides/retrying-transactions.html#facts
*/
maxRetries: 5,
},
)
P/s: I'm using third party api (which is Quicknode for testnet and GetBlock for mainnet).