Overview
The SDK currently supports three additional Solana functions that leverage the priority fee API from the QuickNode Marketplace.
Functions
sendSmartTransaction
Executes the add-on's qn_estimatePriorityFees API call to calculate a priority fee, adds this instruction to your transaction along with optimized compute units, and executes the standard sendTransaction call.
Usage
import { solanaWeb3, Solana } from "@quicknode/sdk";
const { Transaction, SystemProgram, Keypair, PublicKey } = solanaWeb3;
const mainSecretKey = Uint8Array.from([
//redacted
]);
const sender = Keypair.fromSecretKey(mainSecretKey);
const receiver = new PublicKey("redacted");
const senderPublicKey = sender.publicKey;
const endpoint = new Solana({
endpointUrl:
"https://some-cool-name.solana-mainnet.quiknode.pro/redacted",
});
const transaction = new Transaction();
// Add instructions for each receiver
transaction.add(
SystemProgram.transfer({
fromPubkey: senderPublicKey,
toPubkey: receiver,
lamports: 10,
})
);
(async () => {
// Endpoint must have the Priority Fee API add-on enabled to do this
const signature = await endpoint.sendSmartTransaction({
transaction,
keyPair: sender,
feeLevel: "high"
});
console.log(signature);
})().catch(console.error);
Parameters
transaction Transaction object
The @solana/web3js aka QuickNode SDK Transaction object you wish to send.
keyPair Keypair object
The @solana/web3js aka QuickNode SDK Keypair object for the account you wish to send from.
feeLevel string
(optional) Defualt is "medium". The priority level of the fees you wish to allocate, based on estimated compute units for your transaction. Possible values: "extreme", "high", "medium", "low" mapping to the following percentiles: 95th percentile, 80th percentile, 60th percentile, 40th percentile
sendTransactionOptions object
(optional) (SendOptions) configuration:
maxRetries usize
(optional) Default is 'null'. The maximum number of times for the RPC node to retry sending the transaction to the leader. If this parameter is not provided, the RPC node will retry the transaction until it is finalized or until the blockhash expires.
minContextSlot integer
(optional) Default is 'null'. The minimum slot at which the request can be evaluated.
preflightCommitment string
(optional) Default is 'finalized' The commitment level to use for preflight. Possible values: "processed", "confirmed", "finalized", "recent", "single", "singleGossip", "root", "max"
skipPreflight boolean
(optional) Default is false. If true, will skip the preflight transaction checks.
Returns
A promise that resolves to the first transaction signature embedded in the transaction, in base-58 format. The same result as calling the native sendTransaction API method.
prepareSmartTransaction
Executes the add-on's qn_estimatePriorityFees API call to calculate a priority fee and adds this instruction to your transaction along with optimized compute units.
Usage
import { solanaWeb3, Solana } from "@quicknode/sdk";
const { Transaction, SystemProgram, Keypair, PublicKey } = solanaWeb3;
const mainSecretKey = Uint8Array.from([
//redacted
]);
const sender = Keypair.fromSecretKey(mainSecretKey);
const receiver = new PublicKey("redacted");
const senderPublicKey = sender.publicKey;
const endpoint = new Solana({
endpointUrl:
"https://some-cool-name.solana-mainnet.quiknode.pro/redacted",
});
const transaction = new Transaction();
// Add instructions for each receiver
transaction.add(
SystemProgram.transfer({
fromPubkey: senderPublicKey,
toPubkey: receiver,
lamports: 10,
})
);
(async () => {
// Endpoint must have the Priority Fee API add-on enabled to do this
const optimizedTransaction = await endpoint.prepareSmartTransaction({
transaction,
payerPublicKey: sender.publicKey,
feeLevel: "high"
});
return optimizedTransaction;
// proceed to sign and send the new optimized transaction
})().catch(console.error);
Parameters
transaction Transaction object
The @solana/web3js aka QuickNode SDK Transaction object you wish to send.
payerPublicKey publicKey object
The @solana/web3js aka QuickNode SDK publicKey object for the account you wish to send from.
feeLevel string
(optional) Defualt is "medium". The priority level of the fees you wish to allocate, based on estimated compute units for your transaction. Possible values: "extreme", "high", "medium", "low" mapping to the following percentiles: 95th percentile, 80th percentile, 60th percentile, 40th percentile
Returns
A Transaction object now containing a priority fee instruction.
fetchEstimatePriorityFees
Executes the add-on's qn_estimatePriorityFees API call to calculate a priority fee and returns the results.
import { solanaWeb3, Solana } from "@quicknode/sdk";
const { PublicKey } = solanaWeb3;
const programToSearch = new PublicKey("YOUR_PROGRAM_ID");
const numBlocks = 100;
const endpoint = new Solana({
endpointUrl:
"https://some-cool-name.solana-mainnet.quiknode.pro/redacted",
});
(async () => {
// Endpoint must have the Priority Fee API add-on enabled to do this
const recentPriorityFees = await endpoint.fetchEstimatePriorityFees({
last_n_blocks: numBlocks,
account: programToSearch.toBase58(),
});
return recentPriorityFees;
})().catch(console.error);
Parameters
last_n_blocks integer
(optional) Default is 100. Min 0. Max 100. The number of blocks to look back to calculate averages.
account string
(optional) By default will retrieve an account agnostic estimate. Use this parameter to get a more accurate the priority fee calculation, in base58 format.
Returns
A Result object containing the average priority fees over the specified block range.
result object
The result object which contain the following objects:
context object
The context object which contains the following fields:
slot integer
The current slot number.
per_compute_unit object
Estimates for priority fees (in microlamports) based on per-compute-unit metrics.
extreme integer
Fee estimate for extreme priority per compute unit (95th percentile).
high integer
Fee estimate for high priority per compute unit (80th percentile).
medium integer
Fee estimate for medium priority per compute unit (60th percentile).
low integer
Fee estimate for low priority per compute unit (40th percentile).
percentiles object
Fee estimates at various percentiles for per-compute-unit metrics.
per_transaction object
Estimates for priority fees based on per-transaction metrics.
extreme integer
Fee estimate for extreme priority per transaction (95th percentile).
high integer
Fee estimate for high priority per transaction (80th percentile).
medium integer
Fee estimate for medium priority per transaction (60th percentile).
low integer
Fee estimate for low priority per transaction (40th percentile).
percentiles object
Fee estimates at various percentiles for per-transaction metrics.