How to Add Priority Fees to a Transaction | Solana (2024)

Transaction (TX) priority is achieved by paying a Prioritization Fee in additionto the Base Fee. By default the compute budget is the product of 200,000 ComputeUnits (CU) * number of instructions, with a max of 1.4M CU. The Base Fee is5,000 Lamports per signature. A microLamport is 0.000001 Lamports.

Info

You can find a detailed guide here onhow to use priority fees.

The total compute budget or Prioritization Fee for a single TX can be changed byadding instructions from the ComputeBudgetProgram.

ComputeBudgetProgram.setComputeUnitPrice({ microLamports: number }) will add aPrioritization Fee above the Base Fee (5,000 Lamports). The value provided inmicroLamports will be multiplied by the CU budget to determine thePrioritization Fee in Lamports. For example, if your CU budget is 1M CU, and youadd 1 microLamport/CU, the Prioritization Fee will be 1 Lamport (1M *0.000001). The total fee will then be 5001 Lamports.

Use ComputeBudgetProgram.setComputeUnitLimit({ units: number }) to set the newcompute budget. The value provided will replace the default value. Transactionsshould request the minimum amount of CU required for execution to maximizethroughput, or minimize fees.

add-priority-fees.ts

import { BN } from "@coral-xyz/anchor";import { Keypair, Connection, LAMPORTS_PER_SOL, sendAndConfirmTransaction, ComputeBudgetProgram, SystemProgram, Transaction,} from "@solana/web3.js"; (async () => { const payer = Keypair.generate(); const toAccount = Keypair.generate().publicKey;  const connection = new Connection("http://127.0.0.1:8899", "confirmed");  const airdropSignature = await connection.requestAirdrop( payer.publicKey, LAMPORTS_PER_SOL, );  await connection.confirmTransaction(airdropSignature);  // request a specific compute unit budget const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000, });  // set the desired priority fee const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 1, });  // Total fee will be 5,001 Lamports for 1M CU const transaction = new Transaction() .add(modifyComputeUnits) .add(addPriorityFee) .add( SystemProgram.transfer({ fromPubkey: payer.publicKey, toPubkey: toAccount, lamports: 10000000, }), );  const signature = await sendAndConfirmTransaction(connection, transaction, [ payer, ]); console.log(signature);  const result = await connection.getParsedTransaction(signature); console.log(result);})();
How to Add Priority Fees to a Transaction | Solana (2024)
Top Articles
Yendo | The Vehicle Secured Credit Card
What is an HMO?
Menards Thermal Fuse
Canya 7 Drawer Dresser
AllHere, praised for creating LAUSD’s $6M AI chatbot, files for bankruptcy
Uihc Family Medicine
Dew Acuity
Jesus Calling December 1 2022
Embassy Suites Wisconsin Dells
Category: Star Wars: Galaxy of Heroes | EA Forums
123 Movies Babylon
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Infinite Campus Parent Portal Hall County
Cvs Learnet Modules
Troy Athens Cheer Weebly
Craigslist Alabama Montgomery
735 Reeds Avenue 737 & 739 Reeds Ave., Red Bluff, CA 96080 - MLS# 20240686 | CENTURY 21
Viha Email Login
Curry Ford Accident Today
Panic! At The Disco - Spotify Top Songs
Tips on How to Make Dutch Friends & Cultural Norms
Terry Bradshaw | Biography, Stats, & Facts
Tips and Walkthrough: Candy Crush Level 9795
Yonkers Results For Tonight
Cars & Trucks - By Owner near Kissimmee, FL - craigslist
Temu Seat Covers
Yale College Confidential 2027
What Sells at Flea Markets: 20 Profitable Items
Www Craigslist Com Shreveport Louisiana
Craigslist Ludington Michigan
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Timberwolves Point Guard History
Gateway Bible Passage Lookup
511Pa
Arcane Bloodline Pathfinder
Paul Shelesh
John M. Oakey & Son Funeral Home And Crematory Obituaries
Mauston O'reilly's
Lyons Hr Prism Login
Ts In Baton Rouge
DL381 Delta Air Lines Estado de vuelo Hoy y Historial 2024 | Trip.com
Stoughton Commuter Rail Schedule
Plasma Donation Greensburg Pa
Craigslist Cars For Sale By Owner Memphis Tn
Hkx File Compatibility Check Skyrim/Sse
Peugeot-dealer Hedin Automotive: alles onder één dak | Hedin
Law Students
Coldestuknow
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 6302

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.