<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jack Quincy</title>
    <description>The latest articles on DEV Community by Jack Quincy (@jack_quincy_0397ce6381a91).</description>
    <link>https://dev.to/jack_quincy_0397ce6381a91</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1920854%2F5367fdf8-944a-45f3-9e8b-5e5802e53c58.png</url>
      <title>DEV Community: Jack Quincy</title>
      <link>https://dev.to/jack_quincy_0397ce6381a91</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jack_quincy_0397ce6381a91"/>
    <language>en</language>
    <item>
      <title>Help make Solana Transaction faster</title>
      <dc:creator>Jack Quincy</dc:creator>
      <pubDate>Tue, 13 Aug 2024 03:43:37 +0000</pubDate>
      <link>https://dev.to/jack_quincy_0397ce6381a91/help-make-solana-transaction-faster-129l</link>
      <guid>https://dev.to/jack_quincy_0397ce6381a91/help-make-solana-transaction-faster-129l</guid>
      <description>&lt;p&gt;help me make solana transaction faster&lt;br&gt;
`async sendSplTransaction(wallet, {to, value, mintAddress, decimals, fee}) {&lt;br&gt;
        const recipientPubKey = new PublicKey(to);&lt;br&gt;
        const mintPubKey = new PublicKey(mintAddress);&lt;br&gt;
        const bigValue = this.convertToBigInt(value, decimals);&lt;br&gt;
        const recentBlockhash = await this.provider.connection.getLatestBlockhash();&lt;br&gt;
        let currentBlockheight = await this.provider.connection.getBlockHeight();&lt;br&gt;
        const { blockhash } = await this.provider.connection.getLatestBlockhash();&lt;br&gt;
        const MAX_RETRIES = 3;&lt;br&gt;
        let retryCount = 0;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    while (retryCount &amp;lt; MAX_RETRIES) {
        try {
            const senderATA = await getAssociatedTokenAddress(mintPubKey, this.keypair.publicKey);
            const recipientATA = await getAssociatedTokenAddress(mintPubKey, recipientPubKey);

            console.log('Sender pubkey:', this.keypair.publicKey.toString());
            console.log('Sender ATA:', senderATA.toString());
            console.log('Mint address:', mintAddress);

            let senderAccountInfo =  await this.provider.connection.getAccountInfo(senderATA);

            if (!senderAccountInfo) {
                console.log('Sender ATA not found. Attempting to create...');
                const transaction = new Transaction().add(
                    createAssociatedTokenAccountInstruction(
                        this.keypair.publicKey,
                        senderATA,
                        this.keypair.publicKey,
                        mintPubKey
                    )
                );
                await solanaWeb3.sendAndConfirmTransaction(this.provider.connection, transaction, [this.keypair]);
                console.log('Sender ATA created successfully');
            }

            const senderBalance = await this.provider.connection.getTokenAccountBalance(senderATA);
            console.log('Sender token balance:', senderBalance.value.uiAmount);

            if (senderBalance.value.uiAmount &amp;lt; value) {
                throw new Error(`Insufficient balance. Current balance: ${senderBalance.value.uiAmount}`);
            }

            const transaction = new Transaction({
                recentBlockhash: recentBlockhash.blockhash,
                feePayer: this.keypair.publicKey
            });
            transaction.recentBlockhash = blockhash;
            transaction.feePayer = this.keypair.publicKey;
            transaction.fee = fee;

            const recipientAccountInfo = await this.provider.connection.getAccountInfo(recipientATA);

            if (!recipientAccountInfo) {
                transaction.add(
                    createAssociatedTokenAccountInstruction(
                        this.keypair.publicKey,
                        recipientATA,
                        recipientPubKey,
                        mintPubKey
                    )
                );
            }

            transaction.add(
                createTransferInstruction(
                    senderATA,
                    recipientATA,
                    this.keypair.publicKey,
                    bigValue,
                    [],
                    TOKEN_PROGRAM_ID
                )
            );

            transaction.lastValidBlockHeight = currentBlockheight + 150;

            const txid = await solanaWeb3.sendAndConfirmTransaction(
                this.provider.connection,
                transaction,
                [this.keypair],
                {
                    commitment: "confirmed",
                    skipPreflight: true
                }
            );

            console.log('Transaction successful. Txid:', txid);
            return { success: true, data: { txid } };
        } catch (error) {
            if (error.message.includes('block height')) {
                retryCount++;
                const MAX_RETRY_DELAY = 30000;
                const delay = Math.min(2 ** retryCount * 1000, MAX_RETRY_DELAY);
                console.log(`Transaction failed, retrying in ${delay / 1000} seconds...`);
                await new Promise(resolve =&amp;gt; setTimeout(resolve, delay));
            } else {
                return { success: false, data: null, error: error.message };
            }
        }
    }

    return { success: false, data: null, error: 'Transaction retries exhausted.' };
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>solana</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
