You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function is also customizable if you do not like the defaults:
513
+
514
+
```typescript
515
+
const signature =awaitsendTransaction(
511
516
connection,
512
517
transaction,
513
-
signers,
518
+
[payer],
519
+
10000, // priority fee in microLamports
514
520
{
515
-
commitment: "confirmed",
521
+
computeUnitBuffer: { multiplier: 1.1 }, // add 10% buffer to compute units
516
522
onStatusUpdate: (status) =>console.log(status),
517
-
maxRetries: 30,
523
+
commitment: "confirmed",
524
+
maxRetries: 10,
518
525
initialDelayMs: 2000,
519
526
},
520
527
);
521
528
```
522
529
523
-
Best combined with `prepareTransactionWithCompute` to ensure the transaction requests the minimum compute units and sets priority fees.
530
+
The function will:
524
531
525
-
```typescript
526
-
// This could be really nice if RPC providers would all have the same API...
527
-
// Please fall back to the fee api of your favourite RPC provider to get a good value.
528
-
const priorityFee =1000;
532
+
- Skip compute preparation if transaction is already signed
533
+
- Skip compute preparation if transaction already has compute budget instructions
534
+
- Add compute budget instructions if needed
535
+
- Handle retries and confirmation automatically
536
+
- Provide status updates: "created" → "signed" → "sent" → "confirmed"
529
537
530
-
awaitprepareTransactionWithCompute(
531
-
connection,
532
-
tx,
533
-
keyPair.publicKey,
534
-
priorityFee
535
-
);
536
-
537
-
// can either sign the transaction here, or in the sendTransactionWithRetry function
538
-
tx.sign(keyPair);
539
-
540
-
var signature =awaitsendTransactionWithRetry(connection, tx, [], {
541
-
onStatusUpdate: (status) => {
542
-
console.log("Transaction status:", status);
543
-
},
544
-
});
538
+
For RPC providers that support priority fees:
545
539
546
-
```
540
+
- Helius: minimum 10000 microLamports
541
+
- Triton: see their [priority fee API](https://docs.triton.one/chains/solana/improved-priority-fees-api)
542
+
- Quicknode: see their [priority fee estimation](https://www.quicknode.com/docs/solana/qn_estimatePriorityFees)
547
543
548
544
#### `prepareTransactionWithCompute`
549
545
550
-
Prepares a transaction with compute unit calculations and limits. This function:
551
-
552
-
1. Simulates the transaction to determine required compute units
553
-
2. Adds compute budget instructions for both price and unit limit
554
-
3. Supports buffer settings to add safety margins (This is useful when inteacting with defi for examples where the price or route may change during the transaction)
546
+
If you need more control, you can prepare compute units separately:
555
547
556
548
```typescript
557
549
awaitprepareTransactionWithCompute(
558
550
connection,
559
551
transaction,
560
552
payer.publicKey,
561
-
1000, // priority fee in microLamports
553
+
10000, // priority fee
562
554
{
563
555
multiplier: 1.1, // add 10% buffer
564
556
fixed: 100, // add fixed amount of CUs
565
557
},
566
558
);
567
559
```
568
560
569
-
Both functions help with common transaction handling tasks in Solana, making it easier to send reliable transactions with appropriate compute unit settings.
561
+
This will:
562
+
563
+
1. Simulate the transaction to determine required compute units
564
+
2. Add compute budget instructions for both price and unit limit
0 commit comments