using Solnet.Programs;
using Solnet.Wallet;
using Solnet.Rpc;
using Solnet.Rpc.Models;
using System.Collections.Generic;
public class CombinedComputeBudgetExample
{
public void CombinedExample()
{
// Initialize the RPC client (e.g., connect to mainnet)
var rpcClient = ClientFactory.GetClient(Cluster.MainNet);
// Get your fee payer account (replace with your actual account)
var feePayer = new Wallet("YOUR_MNEMONIC_PHRASE").GetAccount(0);
// Define the desired compute unit limit and price
uint computeUnitLimit = 500_000;
ulong computeUnitPrice = 100;
// Create both instructions
var computeLimitInstruction = ComputeBudgetProgram.SetComputeUnitLimit(computeUnitLimit);
var computePriceInstruction = ComputeBudgetProgram.SetComputeUnitPrice(computeUnitPrice);
// Build the transaction with both instructions
var transaction = new TransactionBuilder()
.SetRecentBlockHash(rpcClient.GetLatestBlockHash().Result.Value.Blockhash)
.SetFeePayer(feePayer)
.AddInstruction(computeLimitInstruction)
.AddInstruction(computePriceInstruction)
// Add your transaction's core instructions here
.Build(feePayer);
// Send the transaction
var signature = rpcClient.SendTransaction(transaction);
Console.WriteLine($"Transaction sent. Signature: {signature}");
}
}
While I was tring to compile this code, I face this issue.
"The name 'ComputeBudgetProgram' does not exist in the current context"
I think this error shows ComputeBudgetProgram class doesn't exist in Solnet.Programs package.
How can I increase compute budge limit and set priority fee in C#?
Plz, help me.
Tasadduq BurneyPosted Dec 8, 2025, 5:38 PM
Hey,
Hope you're keeping well.
ComputeBudgetProgramisn’t available in older Solnet builds; it was added in later versions underSolnet.Programs.Utilitiesin the current repo. Update your NuGet package to the latestSolnet(e.g.,dotnet add package Solnet --version x.y.z) and ensure you import the correct namespace. If you must target an older build, construct the compute budget instructions manually usingTransactionInstructionwith the program IDComputeBudget111111111111111111111111111111and encode the parameters per Solana’s spec. This approach lets you setComputeUnitLimitandComputeUnitPricewithout relying on missing APIs.Thanks and regards,
Taz